WordPress.org

Ready to get started?Download WordPress

Forums

Category post count on category archive (3 posts)

  1. Bonnie
    Member
    Posted 8 years ago #

    How would I go about displaying the post count for a particular category actually *on* the category archive page itself?

    I can't use wp_list_cats because this displays a list of all of the category links plus their post counts. All I want is a simple value so I can incorporate it into my category's description. For example:

    "The category you are currently viewing has 56 articles."

    Something like that. Any ideas? It seems so simple but I can't find the tag anywhere!

    Thanks in advance for any help.

  2. Mark Jaquith
    WordPress Lead Dev
    Posted 8 years ago #

    Try this:


    <?php
    if ( is_category() ) : // only run this on category pages
    $this_cat = &get_category($wp_query->get_queried_object_id());
    echo 'The category you are currently viewing has ' . $this_cat->category_count . ' articles';
    endif;
    ?>

  3. Bonnie
    Member
    Posted 8 years ago #

    That works perfectly! Thanks so much! :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags