The sweet and short of this, don’t use get_posts
if you need paginated queries. get_posts
works perfectly if you are going to use a custom query that doesn’t need pagination, but it really becomes a big complicated mess when you need to introduce pagination.
I think the easiest and most appropriate here is to make use of WP_Query
to construct your custom query, that is, if you can’t use pre_get_posts
to alter the main query to get your desired output from the main query.
Also, these two lines are unnecessary, you must delete these
<?php posts_nav_link( $sep, $prelabel, $nextlabel ); ?>
<?php posts_nav_link(); ?>
I do think that next_posts_link()
and previous_posts_link()
is better to use with a custom query, ie with WP_Query
. You must just remember however to set the $max_pages
parameter when you make use of a custom query, otherwise your pagination will break
With a few minor tweaks, your query should look like this
<div id="page-content">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'posts_per_page' =>3, 'order'=> 'ASC', 'orderby' => 'title', 'paged' => $paged );
$postslist = new WP_Query( $args );
if ( $postslist->have_posts() ) :
while ( $postslist->have_posts() ) : $postslist->the_post(); ?>
<div>
<a href="https://wordpress.stackexchange.com/questions/154321/<?php the_permalink(); ?>"><?php the_title(); ?> </a><br />
<small><?php the_time('F jS, Y') ?> by <?php the_author(); ?></small>
<?php the_excerpt(); ?><br />
</div>
<?php endwhile; ?>
<div class="navigation">
<div class="alignleft"><?php next_posts_link( '« Previous Entries', $postslist->max_num_pages ); ?></div>
<div class="alignright"><?php previous_posts_link( 'Next Entries »' ); ?></div>
</div>
<?php wp_reset_postdata();
endif;
?>
</div>