简体   繁体   中英

reverse wordpress query pagination to cache old posts

I'm using wp_query with pagination to load a lot of posts with a custom developed infinite scroll jQuery plugin I made, it takes sometime to load 20 post with thumbnail images and inject them in the DOM everytime the plugin request a new page.

I thought if I can reverse the pagination direction so that page 1 shows the oldest 20 posts (not the recent 20), then the second page shows the next 20 old posts and so on, then I can cache the requests of those pagination links it would make the performance much better.

This way page 1,2,3... should always return the same posts, and the latest page should have the most recent posts.

Does this make any sense? and how can I do it?

Order your posts by date:

WP_Query(array(
    ...,
    "orderby" => "date",
    "order" => 'DESC',
    ...
));

Then force the requested pages to be cached by the browser with jQuery:

$.ajax({
    url: ...,
    type: "GET",
    cache: true,           
    ...
});

Here's more information about the cache parameter in jQuery: https://stackoverflow.com/a/18671689/1123556

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM