Skip to content

Instantly share code, notes, and snippets.

@anilmeena
Last active November 6, 2019 20:39
Show Gist options
  • Save anilmeena/fcab9dd7af46dd452a6bc1d25aee639d to your computer and use it in GitHub Desktop.
Save anilmeena/fcab9dd7af46dd452a6bc1d25aee639d to your computer and use it in GitHub Desktop.
Add ajax based pagination in wordpress loop
<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('&laquo; Older Entries', $new_query->max_num_pages) ?>
<?php previous_posts_link('Newer Entries &raquo;') ?>
</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