Anyone here see why my pagination won't work? I can get "previous page" to show up, but when navigating to "page-2", the content will stay identical to the content on "page-1".

Template Name: Generic Trips Template
<?php get_header(); ?>

        <?php get_template_part( "beforeloop", "page" ) ?>
                                    <?php $types = $post->post_name; ?>

 <?php if (have_posts()) : ?>
     <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts(array( 'post_type' => 'trips', 'types' => $types, "posts_per_page" => 5)); ?>
        <?php while (have_posts()) : the_post(); ?>

                        <article id="post-<?php the_ID(); ?>" class="post">


<?php endwhile; ?>

<?php if(function_exists('wp_pagenavi')) : ?>
                           <div class="pnavi">
            <?php wp_pagenavi(); ?>
        <?php else : ?>
            <div class="alignleft"><?php next_posts_link(__('&laquo; Older Entries')); ?></div>
            <div class="alignright"><?php previous_posts_link(__('Newer Entries &raquo;')); ?></div>
        <?php endif; ?>

<?php endif; wp_reset_query(); ?>

                  <?php get_template_part( "afterloop", "page" ) ?> 

<?php get_footer(); ?>

Don't use query_posts!

As Eugene pointed out, you omitted the paged variable. However, even with that in you can get unexpected behaviour. As illustrated by the various questions we get on query_posts and pagination:


You have to add paged argument to query_posts call. It should look like this:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        'post_type' => 'trips', 
        'types' => $types, 
        'posts_per_page' => 5,
        'paged' => $paged,
    ) );

Read more about WP_Query in codex, especially pagination section.

  • @EugeneManilov Good catch. Unfortunately that didn't help. – WouterB Jun 7 '12 at 14:37

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.