Last active
November 6, 2019 20:39
-
-
Save anilmeena/fcab9dd7af46dd452a6bc1d25aee639d to your computer and use it in GitHub Desktop.
Add ajax based pagination in wordpress loop
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
<div id="content"> | |
<?php | |
$new_query = new WP_Query(); | |
$new_query->query('post_type=post&showposts=1'.'&paged='.$paged); | |
?> | |
<?php while ($new_query->have_posts()) : $new_query->the_post(); ?> | |
<?php the_title(); ?> | |
<?php endwhile; ?> | |
<div id="pagination"> | |
<?php next_posts_link('« Older Entries', $new_query->max_num_pages) ?> | |
<?php previous_posts_link('Newer Entries »') ?> | |
</div> | |
</div><!-- #content --> | |
<script> | |
jQuery(function($) { | |
$('#content').on('click', '#pagination a', function(e){ | |
e.preventDefault(); | |
var link = $(this).attr('href'); | |
$('#content').fadeOut(500, function(){ | |
$(this).load(link + ' #content', function() { | |
$(this).fadeIn(500); | |
}); | |
}); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment