Infinite scroll jquery in wordpress


</pre>
<!-- infinite scroll ends here-->
 <?php if ( $wp_query->max_num_pages > 1 ) :
 if ( $imbalance2_theme_options['navigation'] == 0 ) : // Default ?>

<div>
 <?php next_posts_link( __( 'Load more posts', 'imbalance2' ) ); ?>
 </div>

<script type="text/javascript">
 j('.fetch a').live('click', function(e) {
 e.preventDefault();
 j(this).addClass('loading').text('Loading...');
 j.ajax({
 type: "GET",
 url: j(this).attr('href') + '#category_lists',
 dataType: "html",
 success: function(out) {
 result = j(out).find('#category_lists .category_list_post');
 nextlink = j(out).find('.fetch a').attr('href');
 j('#category_lists').append(result).masonry('appended', result);
 j('.fetch a').removeClass('loading').text('Loading the next set of posts...');
 if (nextlink != undefined) {
 j('.fetch a').attr('href', nextlink);
 } else {
 j('.fetch').remove();
 }
 }
 });
 });
 </script>

<?php elseif ( $imbalance2_theme_options['navigation'] == 1 ) : // Infinite scroll ?>

<div>
 <?php next_posts_link( __( 'Load more posts', 'imbalance2' ) ); ?>
 </div>

<script type="text/javascript">
 // Infinite Scroll
 var href = 'first';
 j(document).ready(function() {
 j('#category_lists').infinitescroll( {
 navSelector : '.infinitescroll',
 nextSelector : '.infinitescroll a',
 itemSelector : '#category_lists .category_list_post',
 loadingImg : '<?php echo get_bloginfo('stylesheet_directory') ?>/images/ajax-loader.gif',

donetext : "<em>Nice! You've hit the end.</em>",
 debug : false
 }, function(arrayOfNewElems) {
 j('#category_lists').masonry('appended', j(arrayOfNewElems));
 if (href != j('.infinitescroll a').attr('href'))
 {
 href = j('.infinitescroll a').attr('href');
 }
 });
 });
 </script>

<?php endif; ?>

<?php endif; ?>
 <!-- infinite scroll ends here-->
<pre>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s