changefreq:页面内容更新频率。
lastmod:页面最后修改时间
loc:页面永久链接地址
priority:相对于其他页面的优先权
首先是准备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.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;
复制代码 这样就可以在你的网站根目录下生成sitemap.xml文件
|
|