This is an experiment trying to implement keyset pagination aka No offset pagination as it was proposed by Markus Winand ( @fatalmind ) on http://use-the-index-luke.com/no-offset to WordPress
The plugin provides custom template tag for displaying next/prev navigation on archive pages (eg.: index.php or archive.php).
no_offset_pagination();
It should be used instead of standard wp_link_pages();
or twentyfourteen_paging_nav();
in case you are working with default Twentyfourteen template.
You can also take advantage of this plugin in your custom development efforts in your plugins or theme functions.php file.
You just have to define extra query_vars for WP_Query.
(Please note: you still must have this plugin installed before nooffset
param is taken into consideration)
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 10,
'nooffset' => array( 'next' => $last_displayed_post_id ) //this is the plugin's specific query_vars definition
);
$query = new WP_Query( $args );
$posts = $query->get_posts();
foreach ( $posts as $post ) {
...
}
For listing previous posts, you have to get the most recent post's ID ( the one displayed as first on your page ) and refer it from nooffset
array this way:
$args = array(
...
'nooffset' => array( 'prev' => $most_recent_displayed_post_id ),
...
);
...
If you are interested how does the produces SQL queries look like, visit the wiki