自動(dòng)生成sitemap地圖php代碼

自動(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ì)答你的

------本頁(yè)內(nèi)容已結(jié)束,喜歡請(qǐng)分享------
溫馨提示:由于項(xiàng)目或工具都有失效性,如遇到不能做的項(xiàng)目或不能使用的工具,可以根據(jù)關(guān)鍵詞在站點(diǎn)搜索相關(guān)內(nèi)容,查看最近更新的或者在網(wǎng)頁(yè)底部給我們留言反饋。
? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊1509 分享
評(píng)論 搶沙發(fā)

請(qǐng)登錄后發(fā)表評(píng)論

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