Use two different post_per_page limits with infinite scroll

I have one loop on my homepage that I use infinite scroll to paginate. To keep the load time of the homepage down, I want to load a smaller initial amount than when the infinite scroll is triggered for the first time. So on page load I want 10 posts loaded and then every trigger after that I want the post_per_page to equal 25. Is that possible? Im using Infinite Scroll Jquery plugin. Not the wordpress version. I use this script after the loop to trigger the infinite scroll.

<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>

Related posts

Leave a Reply

1 comment

    1. Add a parameter to the href URI for the next posts link per JavaScript. For example ?ppp=25.
    2. Add a filter to pre_get_posts, check if ppp is set (and a positive integer) and change the post_per_page parameter accordingly.

    Just an idea, no code, but it should give you a direction. 🙂