亚洲无码视频在线免费看_国产精品福利在线播放_亚洲av优女天堂在线直播_99视频精品热播免费观看

幫助中心

Sitemap對于搜索引擎的收錄很有用,所以每個網(wǎng)站需要一個sitemap.xml,那么標準格式是什么呢?用程序如何來自動生成呢?下面小孚給大家分享一下。

Sitemap的格式是什么?如何用程序生成站點地圖

2020-02-18

Sitemap對于搜索引擎的收錄很有用,所以每個網(wǎng)站需要一個sitemap.xml,那么標準格式是什么呢?用程序如何來自動生成呢?下面小孚給大家分享一下。

sitemap.xml文件的標準格式

<?xml version="1.0" encoding="utf-8"?><!-- XML文件需要使用utf-8編碼--><urlset><!--這個標簽是必須的-->    <url>        <!--也是一個必填標簽,這是具體某一個鏈接的定義入口,每一條數(shù)據(jù)都要用<url>和</url>包含在里面 -->        <loc>http://www.fpapsme.com/news/1.html</loc>        <!--必填,具體的鏈接地址,長度不得超過256字節(jié),如果里面有特殊符號,需要轉義(如:&轉義為&amp;)-->        <lastmod>2020-01-01</lastmod>        <!--選填標簽,用來指定該鏈接的最后更新時間,可以是日期也可以是日期加時間-->        <changefreq>daily</changefreq>        <!--選填標簽,鏈接的更新頻率:always ,hourly ,daily ,weekly ,monthly ,yearly ,never  -->        <priority>0.8</priority>        <!--選填標簽,用來指定此鏈接相對于其他鏈接的優(yōu)先權比值,此值定于0.0-1.0之間-->    </url>    <url>        <loc>http://www.fpapsme.com/news/2.html</loc>        <lastmod>2020-02-01</lastmod>        <changefreq>daily</changefreq>        <priority>0.8</priority>    </url></urlset>?

用PHP來生成sitemap.xml

$sql = "SELECT * FROM " . $ZZUF->table('article') . " ORDER BY id DESC";$thread = $ZZUF->query($sql)->fetchall();// 創(chuàng)建一個DOMDocument對象$dom = new DOMDocument("1.0","utf-8");header("Content-Type: text/xml");// 創(chuàng)建根節(jié)點$root = $dom->createElement("urlset");$dom->appendChild($root);foreach($thread as $key => $row){// 建立根下子節(jié)點track$track = $dom->createElement("url");$root->appendChild($track);// 建立track節(jié)點下元素$loc = $dom->createElement("loc");$track->appendChild($loc);$priority = $dom->createElement("priority");$track->appendChild($priority);$lastmod = $dom->createElement("lastmod");$track->appendChild($lastmod);$changefreq = $dom->createElement("changefreq");$track->appendChild($changefreq);// 獲取到域名$protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://": "http://";$url = $protocol . $_SERVER['HTTP_HOST'];// 賦值$text = $dom->createTextNode($url.'/news/'.$row["id"].'.html');$loc->appendChild($text);$date = date("Y-m-d",time());$text = $dom->createTextNode($date);$lastmod->appendChild($text);$text = $dom->createTextNode(daily);$changefreq->appendChild($text);$text = $dom->createTextNode(0.8);$priority->appendChild($text);}//生成xml文件,路徑根據(jù)自己情況而定$dom->save("sitemap.xml");exit(json_encode(array("state" => 1, "msg" => "新的Sitemap已經(jīng)生成")));


如沒特殊注明,文章均為友孚原創(chuàng),轉載請注明來自:http://www.fpapsme.com/news/7.html