WordPress.org

Support

Support » How-To and Troubleshooting » Category post count on category archive

Category post count on category archive

  • 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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Mark Jaquith

    @markjaquith

    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;
    ?>

    That works perfectly! Thanks so much! 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Category post count on category archive’ is closed to new replies.