cms教程
cms教程 > WordPress > 详情
wordpress非插件实现xml格式网站地图
2020-11-29 16:30 蚂蚁资源网 阅读:197
大家好,今小编要介绍的是关于wordpress非插件实现xml格式网站地图的相关内容,多方面分析说明,感兴趣朋友的可以参考学习。

关键词:WordPress   网站地图  

废话不多说,直接上代码

复制代码代码如下:
<?php
require('./wp-blog-header.php');
header("Content-type: text/xml");
header('HTTP/1.1 200 OK');
$posts_to_show = 1000; // 获取文章数量
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<urlset xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance" rel="external nofollow" >http://www.w3.org/2001/XMLSchema-instance</a>" xmlns="<a href="http://www.sitemaps.org/schemas/sitemap/0.9" rel="external nofollow" rel="external nofollow" >http://www.sitemaps.org/schemas/sitemap/0.9</a>"
xsi:schemaLocation="<a href="http://www.sitemaps.org/schemas/sitemap/0.9" rel="external nofollow" rel="external nofollow" >http://www.sitemaps.org/schemas/sitemap/0.9</a> <a href="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">'" rel="external nofollow" >http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">'</a>;
?>
<!-- generated-on=<?php echo get_lastpostdate('blog'); ?>-->
<url>
<loc>http://localhost/</loc>
<lastmod><?php echo get_lastpostdate('blog'); ?></lastmod>
<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>
<lastmod><?php the_time('c') ?></lastmod>
<changefreq>monthly</changefreq>
<priority>0.6</priority>
</url>
<?php } // end foreach ?>
</urlset>

复制上面代码为xmlmap.php文件并传至网站根目录
http://localhost/xmlmap.php


以上就是wordpress非插件实现xml格式网站地图的全部内容,希望可以帮助到您。感谢对蚂蚁资源网的支持。
(责任编辑:白水满子

版权声明:文章内容是蚂蚁资源网小编精心整合原创的,素材来源于互联网,如无意侵犯到您的权益,请联系网站客服核实版权信息,以便及时删除。
上一篇 下一篇

订单

搜索
蚂蚁资源网

购物车

我的