首页>文档>网络技术>无插件为网站添加sitemap.xml

无插件为网站添加sitemap.xml

网站根目录新建sitemap.php文件

将以下内容写入sitemap.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('https://www.7b3.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;

其中

hangefreq:页面内容更新频率。
lastmod:页面最后修改时间
loc:页面永久链接地址
priority:相对于其他页面的优先权

访问网址/sitemap.php

访问网站链接+/sitemap.php文件后会自动在网站根目录创建sitemap.xml文件!

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索