Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
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 '12 at 10:36
    
I haven't gotten anywhere with it yet. Boggling my mind –  Pollux Khafra Apr 2 '12 at 12:56

2 Answers 2

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;
share|improve this answer
    
What plugin are you using? –  Pollux Khafra Apr 5 '12 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. –  Pollux Khafra Apr 5 '12 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 '12 at 2:12

Add posts_per_page=-1 to your query_posts().

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

share|improve this answer
    
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. –  Pollux Khafra Apr 2 '12 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... –  ialocin Sep 17 '13 at 11:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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