获取所有分类
$args=array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories = get_categories( $args );
foreach($categories as $category) {
$link = get_category_link( $category->term_id );
$count = $category->count;
$name = $category->name;
}
获取分类文章
$args = array(
'category__in' => array( $cats[0] ),
'showposts' => 10,
'orderby' => 'rand', // 随机性
'caller_get_posts' => 1
// 'numberposts' => 5,
'post_status' => 'publish'
);
query_posts( $args );
if (have_posts()) :
while (have_posts()) : the_post();
获取所有标签
$tags = get_tags();
foreach($tags as $tag) {
$link = get_tag_link( $tag->term_id );
$count = $tag->count;
$name = $tag->name;
}
生成 Sitmap.xml
$print = '<?xml version="1.0" encoding="UTF-8"?>
<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
>';
// 获取分类
$args=array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories = get_categories( $args );
foreach($categories as $category) {
$args = array(
'category__in' => array( $category->term_id ),
'showposts' => 10,
// 'orderby' => 'rand', // 随机性
'caller_get_posts' => 1
// 'numberposts' => 5,
// 'post_status' => 'publish'
);
query_posts( $args );
if (have_posts()) :
while (have_posts()) : the_post();
update_post_caches($posts);
$print .= "<url>\r\n";
$print .= "\t<loc>".the_permalink()."</loc>\r\n"
$print .= "\t<priority>0.8</priority>\r\n"
$print .= "\t<lastmod>".the_date()."</lastmod>\r\n"
$print .= "\t<changefreq>weekly</changefreq>\r\n"
$print .= "</url>\r\n"
endwhile;
else :
wp_reset_query();
endif;
}
$print .= '</urlset>';
WP 枚举文章
相关推荐
评论
暂无评论...