loop with the_query instead of query_posts – with pagination
-
This code works for me, but I am trying to stop using query_posts because its supposed to be not good.
<?php query_posts('posts_per_page=2'); ?> <?php if ( have_posts() ) : ?> <?php while ( have_posts() ) : the_post(); ?> <!-- stuff --> <?php endwhile; ?> <div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div> <div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div> <?php else : ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?>so I rewrote it as this, but the pagination doesn’t work.
<?php $the_query = new WP_Query( array( 'posts_per_page' => 2, 'pagination' => true, ) ); ?> <?php if ( $the_query->have_posts() ) : ?> <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <!-- stuff --> <?php endwhile; ?> <div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div> <div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div> <?php else : ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?>Help?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘loop with the_query instead of query_posts – with pagination’ is closed to new replies.