動生成sitemap地圖php代碼,無需調用數據庫,適用于百度站長提交,需要php的環境,本代碼是通過php運行的。
代碼如下:
- <?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.jfrwli.cn/' . (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;
代碼參數說明
changefreq:頁面內容更新頻率。
lastmod:頁面最后修改時間
loc:頁面永久鏈接地址
priority:相對于其他頁面的優先權
百度站長的抓取頻率自己設置,然后吧這個鏈接加入到你的寶塔計劃任務定時訪問url
這樣他就會自動幫你更新了,這個當然你也可以自己修改一下自己需要的參數或URL
具體方法請參考百度,已經與百度達成了深度合作,問他都會答你的