Last active
December 11, 2015 07:28
-
-
Save ccschmitz/4566182 to your computer and use it in GitHub Desktop.
An example of how to load WordPress posts via AJAX.
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
$postsNavBtn.on('click', function(e) { | |
e.preventDefault(); | |
var $loadMoreBtn = $(this), | |
loadMoreText = $loadMoreBtn.text(); | |
$loadMoreBtn.text('Loading...'); | |
// Append the images to the container | |
$('<div/>').load($loadMoreBtn.attr('href') + ' .main-content', function() { | |
var $this = $(this), | |
$newPaginationItems = $this.find('.pagination-items-container').children(), | |
$nextPageBtn = $this.find('.posts-navigation').find('a'); | |
$newPaginationItems.animate({ opacity: 0 }, 0) | |
.appendTo($paginationContainer) | |
.imagesLoaded(function() { | |
$newPaginationItems.animate({ opacity: 1 }); | |
}); | |
if ($nextPageBtn.length > 0) { | |
$loadMoreBtn.attr('href', $nextPageBtn.attr('href')).text(loadMoreText); | |
} else { | |
$loadMoreBtn.fadeOut(); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment