WordPress.org

Forums

[resolved] Display the number of posts within each category page. (5 posts)

  1. southcast
    Member
    Posted 2 years ago #

    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

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    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.

  3. esmi
    Forum Moderator
    Posted 2 years ago #

    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.

  4. alchymyth
    Forum Moderator
    Posted 2 years ago #

    add this in category.php of your theme:

    <?php echo $wp_query->found_posts; ?>
  5. southcast
    Member
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags