How to get Total Post In a Selceted category

I have one solution for you.
This code will show and unordered list with the name of the category and the count of posts containded in it.

<ul class="myClass">
 <?php $categories = get_categories('number=100');
       foreach ($categories as $cat) {
       echo "<li>". $cat->cat_name . " Total posts: ". $cat->category_count ."</li>";
       } ?>
</ul>

Retrieves the 100 first categories

$categories = get_categories('number=100');

and for each of them shows cat_name and category_count

Well the result I presume you really need can now be handled in a var by $cat->category_count, i.e:

$total_num_posts_in_your_category = $cat->category_count

I hope that could help you.

Leave a Comment