首页 > 技术 >自动生成sitemap地图PHP代码

自动生成sitemap地图PHP代码

  • 2024-03-05 14:55:15
  • 3739

代码如下:


<?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;


代码参数说明

changefreq:页面内容更新频率。

lastmod:页面最后修改时间

loc:页面永久链接地址

priority:相对于其他页面的优先权


百度站长的抓取频率自己设置,然后吧这个链接加入到你的宝塔计划任务定时访问url

这样他就会自动帮你更新了,这个当然你也可以自己修改一下自己需要的参数或URL


未经允许不得转载,或转载时需注明出处:茄番番 » 自动生成sitemap地图PHP代码
标签:
关注我们
  • 咨询

  • 公众号