The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Category post count on category archive (3 posts)

  1. Bonnie
    Posted 10 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 10 years ago #

    Try this:

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

  3. Bonnie
    Posted 10 years ago #

    That works perfectly! Thanks so much! :)

Topic Closed

This topic has been closed to new replies.

About this Topic