wordpress通过Linux shell脚本自动生成sitemap.xml
1.在网站根目录(为了安全起见,建议放到一个不会轻易让人找到的路径下)下新建sitemap.php文件,内容如下:
<?php
require('./wp-blog-header.php'); //注意:此处为相对路径,根据实际情况填写
header("Content-type: text/xml");
header('HTTP/1.1 200 OK');
$posts_to_show = 1000; // 获取1000篇文章
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">';
?>
<url>
<loc>http://www.cenliming.com/</loc>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
<?php
header("Content-type: text/xml");
$myposts = get_posts( "numberposts=" . $posts_to_show );
foreach( $myposts as $post ) { ?>
<url>
<loc><?php the_permalink(); ?></loc>
<changefreq>monthly</changefreq>
<priority>0.6</priority>
</url>
<?php } // end foreach ?>
</urlset>
然后保存,退出。
2.然后在网站根目录创建sitemap.xml文件:
touch sitemap.xml
3.crontab 、wget 命令将网站地图内容输出到sitemap.xml中:
crontab -e 0 5 * * * wget -O /xxx/xxx/web/sitemap.xml http://www.cenliming.com/sitemap.php (注:/xxx/xxx/web/为网站根目录)
这样,就可以每天凌晨5点自动的生成网站地图数据了。
关注公众号:拾黑(shiheibook)了解更多
[广告]赞助链接:
四季很好,只要有你,文娱排行榜:https://www.yaopaiming.com/
让资讯触达的更精准有趣:https://www.0xu.cn/
关注网络尖刀微信公众号
随时掌握互联网精彩
随时掌握互联网精彩
赞助链接
排名
热点
搜索指数
- 1 总书记的一周 4959920
- 2 外交部:台湾是中国一省 没独立地位 4932633
- 3 伊朗总统遗体已被送往公墓 4895310
- 4 数据彰显经济运行强劲脉动 4756072
- 5 专家称十年后房子不可能卖白菜价 4657676
- 6 汪峰新女友曾参加《非诚勿扰》 4599469
- 7 吴艳妮登上英国报纸:被赞迷人 4430846
- 8 #狐妖小红娘月红篇# 4312930
- 9 新疆辟谣楼兰故城门票3500元 4241719
- 10 以色列总理涉嫌战争罪被申请逮捕令 4178346