Forums

WP2.1: How to display total number of posts being displayed? (4 posts)

  1. Bob78
    Member
    Posted 5 years ago #

    For WP 2.0.x I had a function which returned the total number of posts and the page number for the current page (if there are more than 10 posts) that are being displayed.

    That is really useful for
    - search results: I've displayed something like "XX posts have been found:"
    - "Page 1 of 5 -- You're browsing category xyz, there are XX posts in this category:"

    etc.

    Could someone help me how to get this information out of WordPress 2.1?

    Many thanks,
    Bob

  2. Bob78
    Member
    Posted 5 years ago #

    Anyone, please? Any hint would be appreciated.

    Thanks,
    Bob

  3. Chris_K
    Member
    Posted 5 years ago #

    And what did your function look like?

  4. Kafkaesqui
    Moderator
    Posted 5 years ago #

    As Handy notes, knowing the function or code you were using would help us suggest changes.

    Typically on category queries I call up the category's info through the get_queried_object() function of the $wp_query class:

    <?php $category = $wp_query->get_queried_object(); ?>

    I can then display number of posts in a category (since it's a record in the categories table) like so:

    <?php echo $category->category_count; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic