0

I know how to show the total number of posts in a site, but is there a way to show the number of posts the page you're on is displaying?

For example, I want to show this at the bottom of each of my blog pages (8 posts per page);

Index - "Showing posts 1 through 8 of 294 total"
Page2 - "Showing posts 9 through 17 of 294 total"
Page3 - "Showing posts 18 through 26 of 294 total"

The posts are displayed in chronological order if that makes a difference.

Is this even possible?

0

This should work, but I haven't tested it:

global $wp_query;
$page = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$ppp = get_query_var('posts_per_page');
$end = $ppp * $page;
$start = $end - $ppp + 1;
$total = $wp_query->found_posts;
echo "Showing posts $start through $end of $total total.";
  • 1
    get_query_var('posts_per_page') will overshoot on the last page of the results (sometimes the first). Has to use $wp_query->post_count. – soulseekah Aug 30 '17 at 18:00
0

Because I'm doing that right now, I tested the last solution and it works except on the last page.

That's working now and tested:

global $wp_query;
$page = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$ppp = get_query_var('posts_per_page');
$end = $ppp * $page;
$start = $end - $ppp + 1;
$total = $wp_query->found_posts;
if ($end > $total)
  $end = $total;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.