How to count posts in loop with infinite scroll?

Question

on my index.php I display all my posts with infinite scroll. Before the WP loop I added a $counter, which counts up with every post. But if the infinite scroll loads new posts, the counter will be reset.

Example for counter:
0
1
2
3
4
5
6
7
(load new posts)
0
1
2
3
4
.
.
.

What can I do that the counter counts up after loading new post (…,6,7,8,9,10,…)?

Thanks for help!

<div class="grid" id="container">
    <div class="grid-sizer"></div>
        <?php $counter = 0;
            if ( have_posts() ) {
                while ( have_posts() ) {
                    the_post();?>
                    <div class="grid-item post-item<?php if($counter % 4 == 0) : ?> opening-box<?php endif; ?>">
                        <?php the_content(); ?>
                    </div>
               <?php $counter++; 
               } // end while
            } ?>
     </div>
</div>
0
, niaker 5 years 2017-10-11T16:20:43-05:00 0 Answers 100 views 0

Leave an answer

Browse
Browse