Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

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

<?php get_header(); ?>

<div id="main">

<?php
// 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 />' ); ?>
    </span>
    <?php the_content(); ?>
    </div>
<?php endforeach; ?>


<?php wp_pagenavi(); ?>
</div>

<?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.

share|improve this question
    
I believe it was my loop that sucked, this is fixed, thanks. –  Phill Mar 4 '12 at 6:01
    
Post your solution for anyone who comes after you to use. –  m0r7if3r Mar 4 '12 at 11:57

2 Answers 2

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.

share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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