GithubHelp home page GithubHelp logo

renowncoder / no-offset-pagination-for-wordpress Goto Github PK

View Code? Open in Web Editor NEW

This project forked from david-binda/no-offset-pagination-for-wordpress

0.0 0.0 0.0 248 KB

License: GNU General Public License v2.0

PHP 100.00%

no-offset-pagination-for-wordpress's Introduction

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

Do not use offset for pagination. Learn why.

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.

(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 ),
  ...
);
...

SQL Queries produced by the plugin

If you are interested how does the produces SQL queries look like, visit the wiki

no-offset-pagination-for-wordpress's People

Contributors

david-binda avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.