废话不多说,直接上代码
<?php require('./wp-blog-header.php'); header("Content-type:text/xml"); header('HTTP/1.1200OK'); $posts_to_show=1000;//获取文章数量 echo'<?xmlversion="1.0"encoding="UTF-8"?>'; echo'<urlsetxmlns:xsi="<ahref="http://www.w3.org/2001/XMLSchema-instance"rel="externalnofollow">http://www.w3.org/2001/XMLSchema-instance</a>"xmlns="<ahref="http://www.sitemaps.org/schemas/sitemap/0.9"rel="externalnofollow"rel="externalnofollow">http://www.sitemaps.org/schemas/sitemap/0.9</a>" xsi:schemaLocation="<ahref="http://www.sitemaps.org/schemas/sitemap/0.9"rel="externalnofollow"rel="externalnofollow">http://www.sitemaps.org/schemas/sitemap/0.9</a><ahref="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">'"rel="externalnofollow">http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">'</a>; ?> <!--generated-on=<?phpechoget_lastpostdate('blog');?>--> <url> <loc>http://localhost/</loc> <lastmod><?phpechoget_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($mypostsas$post){?> <url> <loc><?phpthe_permalink();?></loc> <lastmod><?phpthe_time('c')?></lastmod> <changefreq>monthly</changefreq> <priority>0.6</priority> </url> <?php}//endforeach?> </urlset> 复制上面代码为xmlmap.php文件并传至网站根目录
http://localhost/xmlmap.php