[Resolved] Infinite scroll repeats posts

Home Forums Support [Resolved] Infinite scroll repeats posts

Home Forums Support Infinite scroll repeats posts

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1589662
    Arthur

    I have a homepage with multiple loops. The last loop is repeating posts every time you scroll to the bottom of the page. Here’s the code from that loop:

    <div id="primary" <?php generate_do_element_classes( 'content' ); ?>>
    		<main id="main" <?php generate_do_element_classes( 'main' ); ?>>
    			
    			<h2>Latest Stories</h2>
    			
    			<?php
    			/**
    			 * generate_before_main_content hook.
    			 *
    			 * @since 0.1
    			 */
    			
    			// Exclude posts that have already been added.
    			//$args3['offset'] = 1;
    	
    			
    			
    			$args3 = array(
    			    'post__not_in' => $added_ids,
    			);
    
    			$tier3 = new WP_Query($args3);
    			
    			do_action( 'generate_before_main_content' );
    	 
    			global $added_ids;	 
    			
    			if ( generate_has_default_loop() ) {
    				
    				if ( have_posts() ) :
    
    					while ( $tier3->have_posts() ) :
    						$tier3->the_post();
    
    						generate_do_template_part( 'index' );
    
    							if ($wp_query->current_post !== 0 && ($wp_query->current_post+1)%3 == 0) { 
    								if (function_exists ('adinserter')) {
    								echo adinserter (1); 
    	      					}
    	  					}
    
    					endwhile;
    
    					/**
    					 * generate_after_loop hook.
    					 *
    					 * @since 2.3
    					 */
    					do_action( 'generate_after_loop', 'index' );
    
    				else :
    
    					generate_do_template_part( 'none' );
    
    				endif;
    				
    			}
    
    			/**
    			 * generate_after_main_content hook.
    			 *
    			 * @since 0.1
    			 */
    			do_action( 'generate_after_main_content' );
    			?>
    		</main>
    	</div>
    
    #1589770
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Any sort of pagination on a page with multiple loops is going to cause issues in WordPress. It’s something I’ve played with quite a bit, and there is no easy solution that I know of, unfortunately.

    Infinite scroll in this case looks for posts inside the post container on /page/2 (and so on), and will load those posts into view as you scroll.

    In this case, there are multiple loops inside the post container, so all of those posts will load each time new posts load.

    #1589815
    Arthur

    Ok that is a bit unfortunate. Any recommendations? I would hate to have to switch themes at this point.

    #1591054
    Tom
    Lead Developer
    Lead Developer

    Recommendations to have multiple loops and pagination all work together? I don’t think this a theme thing – it’s a WordPress loop/pagination thing.

    You could try using a plugin for the infinite scroll functionality – perhaps they’ve worked out a solution: https://wordpress.org/plugins/ajax-load-more/

    #1592168
    Arthur

    Ok thank you Tom.

    #1592406
    Tom
    Lead Developer
    Lead Developer

    No problem – let me know if you do find a solution, I’d love to integrate it with GPP.

    #1592435
    Arthur

    As far as the page limit, I removed the default pagination links:

    remove_action( ‘generate_after_loop’, ‘generate_do_post_navigation’ );

    and then output a simpler pagination structure, using ‘next_posts_link’ , which accepts a page limit argument:

    <nav id=”nav-below” class=”paging-navigation”>

    </nav>

    #1593479
    Tom
    Lead Developer
    Lead Developer
    #1593507
    Arthur

    Yep

    #1595107
    Tom
    Lead Developer
    Lead Developer

    Interesting – thanks for letting us know! 🙂

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.