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 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序