玩轉functions.php就可以讓你的Wordpress模板制作得心應手,根據Wordpress標簽別名獲取該tag相關的文章總數,用下面的方法就可以輕松實現。
第一步:把下面的代碼放到functions.php文件中
//Obtain the total number of articles based on tag aliases wodepress.com
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;
}
第二步:在需要顯示的地方放下面的代碼
//Place the following code where it needs to be displayed wodepress.com
<?php echo get_tag_post_count_by_id( $tag_slug ) ?>