1

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>
2
  • Do you use a plugin for the infinitescroll function?
    – janw
    May 8 '12 at 9:54
  • Im using Infinite Scroll Jquery plugin. Not the wordpress version. May 8 '12 at 10:04
0
  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. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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