The other question is completely wrong and should not be used
-
previous_post()
andnext_post()
is both depreciated functions and should not be used anymore -
Never replace
WP_Query
withquery_posts
to solve a problem. This actually creates more. Also,query_posts
should never be used -
showposts
is also depreciated in favor ofposts_per_page
To make pagination work, you will need to do the following instead
-
Set the
paged
parameter in your query arguments (paged=$paged
)$paged = (get_query_var('paged')) ?get_query_var('paged') : 1;
-
Use
previous_posts_link()
andnext_posts_link()
to paginate your posts -
Set the
$max_num_pages
parameter fornext_posts_link()
as to correctly calculate the amount of pages when using a custom query
Your query should look something like this. (Taken from the codex)
<?php
// set the "paged" parameter (use 'page' if the query is on a static front page)
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
// the query
$the_query = new WP_Query( 'posts_per_page=5&paged=' . $paged );
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php
// the loop
while ( $the_query->have_posts() ) : $the_query->the_post();
?>
<?php the_title(); ?>
<?php endwhile; ?>
<?php
// next_posts_link() usage with max_num_pages
next_posts_link( 'Older Entries', $the_query->max_num_pages );
previous_posts_link( 'Newer Entries' );
?>
<?php
// clean up after the query and pagination
wp_reset_postdata();
?>
<?php else: ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>