https://github.com/david-binda/no-offset-pagination-for-wordpress
https://github.com/david-binda/no-offset-pagination-for-wordpress
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/david-binda/no-offset-pagination-for-wordpress
- Owner: david-binda
- License: gpl-2.0
- Created: 2014-09-21T16:53:26.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-09-24T13:25:33.000Z (over 11 years ago)
- Last Synced: 2025-06-04T21:57:26.204Z (about 1 year ago)
- Language: PHP
- Size: 242 KB
- Stars: 11
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
No Offset Pagination for WordPress
==================================
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**
[](http://use-the-index-luke.com/no-offset)
## Template tags usage
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.
## Custom plugin / functions.php usage
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](http://codex.wordpress.org/Class_Reference/WP_Query).
(__Please note:__ _you still must have this plugin installed before ``nooffset`` param is taken into consideration_)
```php
$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:
```php
$args = array(
...
'nooffset' => array( 'prev' => $most_recent_displayed_post_id ),
...
);
...
```
## SQL Queries produced by the plugin
If you are interested how does the produces SQL queries look like, visit the [wiki](https://github.com/david-binda/no-offset-pagination-for-wordpress/wiki/SQL-Queries)