0

I wanted to count number of posts (public, private, protected) according to a category name suppose blog . To get all the posts no matter what category i used $total_pages = wp_count_posts()->publish;

But i cant figure out how to count number of posts for a category name blog

4

1 回答 1

1

This question is answered here:
http://wordpress.org/support/topic/how-to-display-the-number-of-posts-from-a-single-category

<?php
$postsInCat = get_term_by('name','NAMEOFCATEGORY','category');
$postsInCat = $postsInCat->count;
echo $postsInCat;
?>

Or, where 17 is your category id

<?php
wp_list_categories('show_count=1&include=17');
?>
于 2013-11-09T07:01:08.317 回答