Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to show post count in my site by parent category.

Example - We have 18 Tutorials, 15 Article, 3 Freebies

share|improve this question

2 Answers 2

go here..you will find answer

http://jhherren.wordpress.com/2008/08/13/getting-the-number-of-posts-per-category-in-wordpress/

http://codex.wordpress.org/Function_Reference/get_categories

share|improve this answer
    
Answers should be more than links... –  kaiser Oct 11 '12 at 17:19

Here we'll use the function - get_categories() to grab all the available categories and store it as array, Then we'll loop through the array to display the list. Within the foreach loop we did a conditional check that is to determine if category is parent if so print it.

<?php
    $categories = get_categories();
    echo 'We have ';
    foreach($categories as $category) 
    { 
        //to check if category is parent
        if ($category->parent==0)
        {
            echo $category->count . ' '; 
            echo '<a href="' . get_category_link( $category->term_id ) . '">'. $category->name . '</a> , '; 
        }
    }
?>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.