How to find the number of posts in a category (6 posts)

  1. Dalton Rooney
    Posted 10 years ago #

    I'd like to add a line of text to the archive page when people browse by category that says "There are X posts in this category". How do I find out how many posts are in a category?

    I've looked through the forums, I've looked through the codex, to no avail. I know it's possible because the number shows up on the category admin panel, but I can't figure out how it's done.

  2. ladydelaluna
    Posted 10 years ago #

    there's a way to do it in the category links list (in the sidebar, or wherever you happen to have your categories listed out)... so that after the category title, a number in parenthesis shows up saying how many posts...


    you'd use something like this (but read the above link to determine exactly what you want):

    <?php wp_list_cats('sort_column=name&optioncount=1'); ?>

    It's the optioncount=1 that will give you the number...

  3. Dalton Rooney
    Posted 10 years ago #

    Right, but displaying the entire list of categories unfortunately isn't an option in this case. I was kinda hoping there was some sort of hidden option for single_cat_title(), but that seems unlikely.

    How do they do it in the category admin section?

  4. Dalton Rooney
    Posted 10 years ago #


  5. Jauhari
    Posted 10 years ago #

    I want display count only on child but on Main categories the count will gone. How to do that?

  6. hip
    Posted 9 years ago #

    Hi daltonrooney,

    I've just posted what may be a solution to your q.


    Have a good day,

Topic Closed

This topic has been closed to new replies.

About this Topic