WordPress.org

Ready to get started?Download WordPress

Forums

Count the posts on a page (4 posts)

  1. Niekje
    Member
    Posted 1 year ago #

    Hi everyone,

    For some while now I have been trying to find a solution for the following: On top of my blogpage I want to show how many posts that current page is showing, so lets say the page has 9 posts I want the page to return viewing post 1 to 9 from 28 total.

    Also when you use the post/page navigation going for example to: http://www.myblog.com/myblog/page/2/ it should say post 9 to 18 from 28 total.

    I wonder if anyone has ever done something like that and would like to share it with me, I greatly appreciate it.

    Kind regards

  2. vtxyzzy
    Member
    Posted 1 year ago #

    The WP PageNavi plugin will do at least part of what you want.

  3. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    try this code:

    <?php
    echo 'post ' . (1+get_query_var('posts_per_page')*(get_query_var('paged')?get_query_var('paged')-1:0)) . ' to ' . ($wp_query->post_count+get_query_var('posts_per_page')*(get_query_var('paged')?get_query_var('paged')-1:0)) . ' of ' . $wp_query->found_posts . ' total';
    ?>

    uses:

    get_query_var('posts_per_page') = your settings under dashboard - settings- - reading - Blog pages show at most [ ] posts;

    get_query_var('paged') = which paginated page you are on

    $wp_query->post_count = the actual number of posts on this paginated page;

    $wp_query->found_posts = number of all posts for this query.

  4. Niekje
    Member
    Posted 1 year ago #

    Thanks allot alchymyth, I really appreciate the help.

    I tried out your code and it works fine for normal WordPress 'posts'. Now I only need to figure out how I can set it up to work with the WordPress Shopp plugin. As far as I know that plugin does not use the normal '$wp_query' but I will check that out later.

    @vtxyzzy thanks for your answer but I know that plugin and it does not do what I need.

    Kind regards

Topic Closed

This topic has been closed to new replies.

About this Topic