dousa1630 2014-12-12 14:22
浏览 47
已采纳

Jquery为自定义帖子类型的Wordpress加载更多按钮

I am trying to add a load more button to my wordpress website, to load my custom post types. So far I have been able to make it load the posts.

The problem is that every time I load more posts it replaces the first batch witch the second and so on. I want it to append every consecutive batch of posts to the first batch until the are no more (max_num_pages) posts left after that the button should deactivate.

How would I go about achieving this? Suggestions and improvements will be greatly appreciated. This is what I have so far.

<div id="div1"></div>
<button class="load-more">load more</button>

var clicks = 0;

$(".load-more").click(function(){
clicks += 1;

if(clicks < 2){
$("#div1").load("http://mysite.nl/loadmore/");
    } else if(clicks > 1) {
        $("#div1").load("http://mysite.nl/loadmore/page/" + clicks);
    }
});
  • 写回答

1条回答 默认 最新

  • dr637349 2014-12-12 14:25
    关注

    Using $("#div1").load() will replace all the HTML in #div1. I'd say load your new data on a hidden element then .append() that new data to #div1.

    Or

    ...perhaps you can save the existing #div1 HTML to a variable:

    var foo = $('#div1').html();
    

    then load your new data and afterwards .prepend() the original:

    $('#div1')
        .load("http://...")
        .prepend(foo);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭