Infinite-Scroll requests numerical page that doesn’t exist in Masonry
-
I’m trying to combine Masonry with Infinite-Scroll, both from Metafizzy website, so that when I scroll downwards, it’ll automatically grab previous posts.
The Infinite-Scroll works but it only calls one post from
blog/page/2
whereas it has three posts, but each time I scroll downwards a new post spawns on-top overlapping each other and the appended item does not align with the rest of the masonry grid either.When I scroll back up and down again it begins to call
blog/page/3
, however I didn’t make many posts so the 3rd page does not exist.Functions
function enqueue_masonry() { wp_enqueue_script( 'masonry', get_template_directory_uri() . '/js/masonry.js', array( 'jquery' ), '', true ); wp_enqueue_script( 'jquery-masonry', true ); wp_enqueue_script('masonry', true); wp_enqueue_script( 'infinitescroll', get_template_directory_uri() . '/js/infinite-scroll.pkgd.min.js', array( 'jquery' ), '', true ); } add_action( 'wp_enqueue_scripts', 'enqueue_masonry');
Section Index
<div class="js-masonry"> <?php if( have_posts() ): while( have_posts() ): the_post();?> <div class="item-masonry overlay"> <a href="<?php the_permalink();?>"> <div class="posts"> <?php foreach((get_the_category()) as $category) {echo $category->cat_name . ' ';}?> <h1><?php the_title();?></h1> ———— <h4><?php the_author();?></h4> </div> <img src="<?php the_post_thumbnail_url('');?>"/> </a> </div> <?php endwhile; else: endif;?> </div> <p class="pagination"> <a class="pagination__next"><?php next_posts_link( 'Older Entries »', 0 ); ?></a> </p>
Index
<div class="masonry"> <?php get_template_part('includes/section','index');?> </div> <script> var msnry = document.querySelector('.masonry'); var msnry = new Masonry( msnry, { itemSelector: '.item-masonry', columnWidth: '.size-masonry' }); var infScroll = document.querySelector('.masonry'); var infScroll = new InfiniteScroll( '.masonry', { path: 'page/{{#}}', append: '.item-masonry', debug: true, hideNav: '.pagination', outlayer: msnry, }); </script>
I’ve tried changing the path to
pagination__next
but it doesn’t do anything.
- The topic ‘Infinite-Scroll requests numerical page that doesn’t exist in Masonry’ is closed to new replies.