duanao2585 2017-02-21 22:37
浏览 23

反向wordpress查询分页以缓存旧帖子

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?

  • 写回答

1条回答 默认 最新

  • dragon7713 2017-02-21 22:57
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3