I manage to get the Ajax loading to load wordpress post. But my problem is when I click the next posts button it replaces the previous post with new posts. But I want to display next set of post below the posts that are already displayed but not replace them.
Till now.
<div id="content">
<div id="contentInner">
<ul class="list-group">
<!-- the loop -->
<?php if ( have_posts() ) : while (have_posts()) : the_post(); ?>
<!-- the title, the content etc.. -->
<?php get_template_part( 'content', get_post_format() );?>
<?php endwhile; ?>
<!-- pagination -->
<ul id='Pagination'>
<li>< ?php next_posts_link('NEXT »') ?></li>
</ul>
<?php else : ?>
<!-- No posts found -->
<?php get_template_part( 'content', 'none' );
endif; ?>
</ul>
</div>
</div>
And the script.
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery(document).on('click','#Pagination a', function(e){
e.preventDefault();
var link = jQuery(this).attr('href');
jQuery('#content').html('Loading...');
jQuery('#content').load(link+' #contentInner');
});
});</script>