网站建设任意网站添加生成sitemap地图

[复制链接]
查看2429 | 回复0 | 2021-3-12 08:31 | 显示全部楼层 |阅读模式
changefreq:页面内容更新频率。
lastmod:页面最后修改时间
loc:页面永久链接地址
priority:相对于其他页面的优先权
首先是准备php的环境,本代码是通过php运行的
上代码
  1. <?php
  2. $dom = new DOMDocument("1.0", "utf-8");
  3. header("Content-Type: text/xml");
  4. $root = $dom->createElement("urlset");
  5. $dom->appendChild($root);
  6. for ($i = 0; $i <= 998; $i++) {
  7.     $track = $dom->createElement("url");
  8.     $root->appendChild($track);
  9.     $loc = $dom->createElement("loc");
  10.     $track->appendChild($loc);
  11.     $lastmod = $dom->createElement("lastmod");
  12.     $track->appendChild($lastmod);
  13.     $changefreq = $dom->createElement("changefreq");
  14.     $track->appendChild($changefreq);
  15.     $priority = $dom->createElement("priority");
  16.     $track->appendChild($priority);
  17.     $text = $dom->createTextNode('http://www.baidu.com/' . (mt_rand(1,20)) . ($i+1) . '.html');
  18.     $loc->appendChild($text);
  19.     $date = date("Y-m-d", strtotime('-' . rand(0,10) . 'day'));
  20.     $text = $dom->createTextNode($date);
  21.     $lastmod->appendChild($text);
  22.     $text = $dom->createTextNode(daily);
  23.     $changefreq->appendChild($text);
  24.     $text = $dom->createTextNode(0.8);
  25.     $priority->appendChild($text);
  26. }
  27. $dom->save("sitemap.xml");
  28. exit;
复制代码
这样就可以在你的网站根目录下生成sitemap.xml文件

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

UID
1
贡献
387
丢币
38902
主题
4607
回帖
116
注册时间
2018-9-25
最后登录
2024-4-26