自動(dòng)生成sitemap地圖php代碼,無(wú)需調(diào)用數(shù)據(jù)庫(kù),適用于百度站長(zhǎng)提交。
需要php的環(huán)境,本代碼是通過(guò)php運(yùn)行的。
自動(dòng)生成sitemap代碼如下:
<?php
$dom = new DOMDocument("1.0", "utf-8");
header("Content-Type: text/xml");
$root = $dom->createElement("urlset");
$dom->appendChild($root);
for ($i = 0; $i <= 998; $i++) {
$track = $dom->createElement("url");
$root->appendChild($track);
$loc = $dom->createElement("loc");
$track->appendChild($loc);
$lastmod = $dom->createElement("lastmod");
$track->appendChild($lastmod);
$changefreq = $dom->createElement("changefreq");
$track->appendChild($changefreq);
$priority = $dom->createElement("priority");
$track->appendChild($priority);
$text = $dom->createTextNode('http://www.baidu.com/' . (mt_rand(1,20)) . ($i+1) . '.html');
$loc->appendChild($text);
$date = date("Y-m-d", strtotime('-' . rand(0,10) . 'day'));
$text = $dom->createTextNode($date);
$lastmod->appendChild($text);
$text = $dom->createTextNode(daily);
$changefreq->appendChild($text);
$text = $dom->createTextNode(0.8);
$priority->appendChild($text);
}
$dom->save("sitemap.xml");
exit;
代碼參數(shù)說(shuō)明changefreq:頁(yè)面內(nèi)容更新頻率。lastmod:頁(yè)面最后修改時(shí)間loc:頁(yè)面永久鏈接地址priority:相對(duì)于其他頁(yè)面的優(yōu)先權(quán)
百度站長(zhǎng)的抓取頻率自己設(shè)置,然后吧這個(gè)鏈接加入到你的寶塔計(jì)劃任務(wù)定時(shí)訪問(wèn)url
這樣他就會(huì)自動(dòng)幫你更新了,這個(gè)當(dāng)然你也可以自己修改一下自己需要的參數(shù)或URL
具體方法請(qǐng)參考百度,已經(jīng)與百度達(dá)成了深度合作,問(wèn)他都會(huì)答你的














暫無(wú)評(píng)論內(nèi)容