On my page I've got a query that retrieves posts with specific parameters and I'm displaying one post per page with pagination. I've figured out how to get the total count of posts found by the query. I want to add some navigation that essentially says "You're looking at 'n' of 25 posts" and have 'n' increase or decrease as the user clicks through the 'Next Post/Previous Post' links.

Is there a function already in place for this?

Here's my query and how I'm outputting it to the page:

        $display_count = 1;
        $page = get_query_var('paged') ? get_query_var('paged') : 1;
        $offset = ($page -1)*$display_count;
        $query_args = array(
            'post_type' => 'post',
            'orderBy' => 'date',
            'order' => 'desc',
            'number' => $display_count,
            'posts_per_page' => 1,
            'page' => $page,
            'offset' => $offset
<article id="portfolio_item">
      <?php $portfolio = new WP_Query($query_args); ?>
      <!-- Total number of posts -->
      <p> <?php echo "There are ".$portfolio->found_posts." Planning Projects"; ?></p>
      <!-- Pagination Links -->
                <?php previous_posts_link( '<< Previous Posts | ', $portfolio->max_num_pages ); ?>
                <?php next_posts_link( 'Next Posts >>', $portfolio->max_num_pages ); ?>
        <?php if( $portfolio->have_posts() ) : while( $portfolio->have_posts()) : $portfolio->the_post(); ?>
      <h2><?php the_title() ?><span id="project_location"> <?php echo get_post_meta($post->ID, 'project_location', true) ?></span> <span id="project_class">{ <?php echo get_post_meta($post->ID, 'project_services', true) ?> }</span></h2>
        <?php the_content() ?>
        <?php endwhile; endif; ?>
        <?php wp_reset_query(); ?>
  • 2
    You mean "Page $page of $portfolio->found_posts."?
    – fuxia
    Mar 21, 2013 at 19:42
  • Exactly, That's what I'm looking for!
    – Ofeargall
    Mar 21, 2013 at 19:48
  • Worked like a charm. Can you make an answer so I can give credit where awesome credit is due? Thank you!
    – Ofeargall
    Mar 21, 2013 at 19:50
  • I do that right now. :)
    – fuxia
    Mar 21, 2013 at 19:52

1 Answer 1


You have all the necessary variables already at hand: $page is the current page number, and $portfolio->found_posts the total number of posts.

Both should be integers, but to be sure and to keep the code translatable I would use something like this:

$current = sprintf(
        'Page %1$d of %2$d.',  // default string
        '1 = current page, 2 = total pages', // context information for translators

echo '<p>' . esc_html( $current ) . '</p>';

So nothing dangerous can happen, even if a translator injects some HTML.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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