Support » Fixing WordPress » Category Post Count not displayed

  • Resolved Debugger

    (@retrobeatcom)


    Hello,
    i have a the fowling code into my sidebar:

    <?php wp_list_categories('orderby=name&show_count=1&title_li='); ?>

    The above code displays all my categories and sub-categories including the number of posts in every category.

    I tried to include only one of my categories, so i change the above code to:

    <?php wp_list_categories('orderby=name&show_count=1&title_li=&include=22'); ?>

    The above code gives no results, it returns “NO CATEGORIES”.
    In category 22 there are no posts but +20 sub-categories.

    If i change it to:

    <?php wp_list_categories('orderby=name&show_count=1&title_li=&child_of=22'); ?>

    It returns all of the sub-categories but that’s not what i need.

    I need only the main category with ID 22 to be displayed with the number of all posts inside sub-cateegories.

    Any kind of help will be well appreciated.
    Regards

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator keesiemeijer

    (@keesiemeijer)


    moderator


    Try it with this:

    <?php
    $categories = get_categories('child_of=22');
    $count = 0;
    foreach($categories as $cat) {
    	$count += $cat->count;
    }
    ?>
    <a href="<?php echo esc_url( get_category_link( 22 ) ); ?>"><?php echo get_cat_name( 22 )  ?> (<?php echo $count; ?>)</a>

    Thanks so much!
    That worked just how i needed to 🙂
    Thank You again!

    Moderator keesiemeijer

    (@keesiemeijer)


    moderator


    You’re welcome. I’m glad you’ve got it resolved 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Category Post Count not displayed’ is closed to new replies.