require('./wp-blog-header.php');
header("Content-type: text/xml");
header('HTTP/1.1 200 OK');
$posts_to_show = 1000;
echo '';
echo '
'
daily
1.0
/* 文章页面 */
header("Content-type: text/xml");
$myposts = get_posts( "numberposts=" . $posts_to_show );
foreach( $myposts as $post ) { ?>
monthly
0.6
/* 单页面 */
$mypages = get_pages();
if(count($mypages) > 0) {
foreach($mypages as $page) { ?>
ID); ?>
ID)->post_modified); ?>+00:00
weekly
0.6
/* 博客分类 */
$terms = get_terms('category', 'orderby=name&hide_empty=0' );
$countcount = count($terms);
if($count > 0){
foreach ($terms as $term) { ?>
slug); ?>
weekly
0.8
/* 标签(可选) */
$tags = get_terms("post_tag");
foreach ( $tags as $key => $tag ) {
$link = get_term_link( intval($tag->term_id), "post_tag" );
if ( is_wp_error( $link ) )
return false;
$tags[ $key ]->link = $link;
monthly
0.4
添加伪静态规则:
Apache:
RewriteRule ^(sitemap)\.xml$ $1.php
Nginx:
rewrite ^/sitemap.xml$ /sitemap.php last;