WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Display the number of posts within each category page.

[Resolved] Display the number of posts within each category page.

  • southcast

    @southcast

    Just to let you know guys that I have searched the forum thoroughly to find a solution before making this post.
    What I want to achieve is echo/display on my category page ( on each of my category pages), a simple numerical value for the number of posts within that category. Something like the example given below :

    Posts in this category : 86

    I hope I was clear enough. Anybody up for suggesting me a code to achieve this please.
    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • esmi

    @esmi

    Forum Moderator

    Try using:

    <p class="num-posts">Posts in this category : <?php echo $wp_query->max_num_pages;?></p>

    outside of the Loop in your theme’s category template file.

    esmi

    @esmi

    Forum Moderator

    Sorry – mistake. That should be $wp_query->found_posts. I’m trying to disentangle the variables from a function I wrote that did something very similar and I disentangled the wrong variable.

    Michael

    @alchymyth

    Forum Moderator

    add this in category.php of your theme:

    <?php echo $wp_query->found_posts; ?>
    southcast

    @southcast

    @esmi and @alchymyth. Thanks a million guys ! The solution was accurate and the response was blazing fast !! Marking it resolved.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] Display the number of posts within each category page.’ is closed to new replies.
Skip to toolbar