I am using a page template with code to display all blog posts:

<?php /* Template Name: Blog */ ?>

<?php get_header(); ?>

<div id="main">

// ACF Page number variable
$numposts = get_field('number_of_posts_per_page');
$args = array( 'numberposts' => $numposts );
$lastposts = get_posts( $args );
foreach($lastposts as $post) : setup_postdata($post);

    <div class="blogpost clearfix">
    <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    <span class="postdetails">
    <?php the_time ('j F, Y'); ?>&nbsp;&nbsp;<span class="bullet">&bull;</span>&nbsp;&nbsp;Posted by:&nbsp;<?php the_author(', '); ?>&nbsp;in:&nbsp;<?php the_category(', '); ?><?php the_tags( '&nbsp;&nbsp;<span class="bullet">&bull;</span>&nbsp;&nbspTags: ', ', ', '<br />' ); ?>
    <?php the_content(); ?>
<?php endforeach; ?>

<?php wp_pagenavi(); ?>

<?php get_footer(); ?>

The problem I'm having is I cannot get any pagination to work. Above I have pagenavi installed but nothing appears. I have set the post limit to 5 in both my custom field (which shows 5, there are 6 posts) and in WP settings.

Can anyone shed any light? Thanks.

  • I believe it was my loop that sucked, this is fixed, thanks.
    – Phill
    Commented Mar 4, 2012 at 6:01
  • Post your solution for anyone who comes after you to use.
    – mor7ifer
    Commented Mar 4, 2012 at 11:57

2 Answers 2


probably coz you override the default query and forgot to take care of pagination :-) change the code this way:

$page = isset(get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'numberposts' => $numposts, 'paged' =>  $paged );

This should do the work


I have to say it's unusual to see someone using a custom template for a blog considering the index.php is for this; I guess it depends on your set up. I'd suggest being careful whenever doing custom queries.

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.