-
-
Save MichaelXavier/3012115 to your computer and use it in GitHub Desktop.
Ajax from PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | |
var element = $(html); | |
//preprocess HTML before inserting into DOM | |
element.find('.article-container, .article-container-grid').each(function() { | |
// IF ID DOES EXIST, ADD CLASS TO ARTICLE CONTAINER | |
if(cookieValue.indexOf($(this).data('id')) != -1) { | |
$(this).addClass('readit'); | |
if(!appended) { | |
$('<h4 class="readit-alert">You've read it!</h4>').appendTo('.article-container.readit, .article-container-grid.readit'); | |
appended = true; | |
} | |
} else { | |
// OTHERWISE, ADD CLASS NOT READ | |
$(this).addClass('notread'); | |
appended = false; | |
} | |
}); | |
loader.fadeOut(500); | |
$('#main-content').append(element); | |
} | |
}); | |
return false; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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