Skip to content

Instantly share code, notes, and snippets.

@chillybin
Created October 22, 2018 07:52
Show Gist options
  • Save chillybin/4abed9cc68f16d270680ba9a7b955928 to your computer and use it in GitHub Desktop.
Save chillybin/4abed9cc68f16d270680ba9a7b955928 to your computer and use it in GitHub Desktop.
$("footer.infinite a").click(function(e){
loadArticle();
e.preventDefault();
});
function loadArticle() {
$("footer.infinite a").html("...");
var offset = $("footer.infinite a").data("count");
var num = parseInt(offset, 10);
var cat = $("footer.infinite a").data('cat');
var loading = $("footer.infinite a").data('loading');
if(loading == 0){
$("footer.infinite a").data('loading',"1");
$.ajax({
url: "//" + location.host + "/wp-admin/admin-ajax.php",
type:'POST',
data: {
action: 'infinitescroll',
offset: num,
category: cat
},
success: function(html){
var off = $("footer.infinite a").data('count');
off = parseInt(off, 10) + 5;
$("footer.infinite a").data('loading',"0");
if(html == ''){
$("footer.infinite a").html('done');
}
else {
$("footer.infinite").before(html);
$("footer.infinite a").data("count", off);
$("footer.infinite a").html("more");
}
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment