ccschmitz
1/18/2013 - 5:10 PM

An example of how to load WordPress posts via AJAX.

An example of how to load WordPress posts via AJAX.

$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();
		}
	});
});