Skip to content

Instantly share code, notes, and snippets.

@dplummer
Forked from anonymous/CFBFeatures
Created June 27, 2012 23:20
Show Gist options
  • Save dplummer/3007536 to your computer and use it in GitHub Desktop.
Save dplummer/3007536 to your computer and use it in GitHub Desktop.
Ajax from PHP
var count = 2;
var loader = $('.infinite-loader');
$(window).scroll(function() {
if($(window).scrollTop() == $(document).height() - $(window).height()) {
if(count > total) {
return false;
} else {
loadInfiniteContent(count);
}
count++;
}
});
function loadInfiniteContent(pageNumber) {
loader.fadeIn(500);
$.ajax({
url: '/wp-admin/admin-ajax.php',
type: 'POST',
data: 'action=infinite_scroll&page_no=' + pageNumber + '&loop_file=loop',
success: function(html) {
loader.fadeOut(500);
$('#main-content').append(html);
}
});
return false;
}
function wp_infinitepaginate(){
$loopFile = $_POST['loop_file'];
$paged = $_POST['page_no'];
$posts_per_page = get_option('posts_per_page');
query_posts(array('paged' => $paged ));
get_template_part( $loopFile );
exit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment