wordpress统计某个标签下的文章总数
在某个页面,我们需要在其后面显示此标签下共有多少文章,做个统计,可以用下面的两个函数来调用。
//根据标签ID获取文章数
function get_tag_post_count_by_id( $tag_id ) {
$tag = get_term_by( "id", $tag_id, "post_tag" );
_make_cat_compat( $tag );
return $tag->count;
}
//根据标签别名获取文章数
function get_tag_post_count_by_slug( $tag_slug ) {
$tag = get_term_by( "slug", $tag_slug, "post_tag" );
_make_cat_compat( $tag );
return $tag->count;
}