0

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

<?php
/*
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">


                        </article>

<?php endwhile; ?>

<?php if(function_exists('wp_pagenavi')) : ?>
                           <div class="pnavi">
            <?php wp_pagenavi(); ?>
                           </div>
        <?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(); ?>
4

2 Answers 2

1

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:

1

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

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

Read more about WP_Query in codex, especially pagination section.

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

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.