0

Im using masonry with infinite scroll to display posts in a loop. I set the post per page which works great on the index page but when I place that same loop on a single page or a buddypress profile page then it only displays the first set of post per page and when I scroll down it returns no more posts to show. Heres the loop minus the guts.

<div id="boxes">
<?php
 query_posts("cat=-1&r_sortby=highest_rated&posts_per_page=8paged=".get_query_var('paged'));
   if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
   <ul>
     <li>
     </li>
    </ul>
    <?php endwhile; ?>
  <?php endif; ?>
</div>
<div class="infinitescroll">
<?php next_posts_link( __( 'Load more posts', 'imbalance2' ) ); ?>
</div>

<script type="text/javascript">
 // Infinite Scroll
 var href = 'first';
 $(document).ready(function() {
$('#boxes').infinitescroll({
    navSelector : '.infinitescroll',
    nextSelector : '.infinitescroll a',
    itemSelector : '#boxes .box',
    loadingImg : '<?php echo get_bloginfo('stylesheet_directory') ?>/images/loading.gif',
    loadingText : 'Loading...',
    donetext : 'No more pages to load.',
    debug : false
}, function(arrayOfNewElems) {
    $('#boxes').masonry('appended', $(arrayOfNewElems));
    if (href != $('.infinitescroll a').attr('href'))
    {
        href = $('.infinitescroll a').attr('href');
    }
});
 });
</script>

Any idea why it's behaving differently on non index pages?

2
  • I am also having this problem! I need infinite scroll to work on the pages rather than the index and its giving me a bit of a headache...
    – martynr
    Apr 2, 2012 at 10:36
  • I haven't gotten anywhere with it yet. Boggling my mind Apr 2, 2012 at 12:56

2 Answers 2

1

Okay I've found the solution infinite scroll not working on certain pages. It seems that it is set by default to not load on any Page or Single. You can edit the plugin easily to remove the checks but be aware that upgrading the plugin in future will override the changes and you'll need to repeat them (unless they add a menu option to remove the need for the hack).

http://wordpress.org/support/topic/loading-infinite-scroll-in-a-custom-header-for-a-page?replies=4

I removed is_page() from the following code and now it works:

if(is_page() || is_single() || !have_posts())
        $load_infinite_scroll = false;
3
  • What plugin are you using? Apr 5, 2012 at 0:18
  • my infinite scroll is only triggered by this statement if ( $wp_query->max_num_pages > 1 ) : and the loop isn't telling it that there are more than 1 page. Apr 5, 2012 at 0:33
  • I'm just using the latest wordpress plugin wordpress.org/extend/plugins/infinite-scroll Infinite scroll is triggered by the presence of the pagination div. If you only have one page of content then that pagination shouldn't appear and infinite scroll won't be triggered. Therefore you shouldn't need your extra if statement to control it.
    – martynr
    Apr 5, 2012 at 2:12
-1

Add posts_per_page=-1 to your query_posts().

This will query all posts and be limited to the global stting.

2
  • I accidentally left out the already added post-per-page limit when I was tinkering with it. The post per page actually needs to be 8 and the problem is when it's set to 8 it doesn't load any posts after the 8. It will on the index page and search but nowhere else. It shows no more posts to load when scrolled down. Apr 2, 2012 at 14:34
  • This isn't a solution for the question at all, because the only thing this does is to show all posts and if you do that there really isn't the necessity to deal with infinite scroll... Sep 17, 2013 at 11:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.