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.

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>
share|improve this question
    
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. –  Pollux Khafra May 8 '12 at 10:04

1 Answer 1

up vote 0 down vote accepted
  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. :)

share|improve this answer

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.