• Site Link

    Using _s theme with Jetpack Infinite module activated.

    On first scroll (after 9 posts) you can see that two posts are getting repeated. I’ve tried many things provided on forums and stack overflow but nothing is working.

    Following is the code –

    functions.php

    function vg_get_prod_arch_posts( $post_type = 'post' ) {
    
    	$prodarch_posts = get_posts( array(
    		'numberposts' => 9,
    		'post_type'   => $post_type
    	) );
    
    	return $prodarch_posts;
    
    }
    
    function vg_infinite_scroll_init() {
    	add_theme_support( 'infinite-scroll', array(
    	    'container' 		=> 'row-wrap',
    	    'type'   			=> 'scroll',
    	    'render'        	=> 'loop_p_arch_infinite_scroll_render',
    	    'footer'			=> false,
    	    'footer_widgets' 	=> false,
    	    'wrapper'			=> false,
    	) );
    }
    
    add_action( 'after_setup_theme', 'vg_infinite_scroll_init' );
    
    function loop_p_arch_infinite_scroll_render() {
    
    	while( have_posts() ) {
    		the_post();
    		if ( is_post_type_archive( 'products' ) ) {
    			get_template_part( 'content', 'products' );
    		}
    	}
    
    }

    archive-products.php

    <h5>Featured Product</h5>
    
    <div class="sidebar-sept">
    
    </div>
    
    <div class="row" id="row-wrap">
    
    	<?php
    	$products = vg_get_prod_arch_posts( 'products' );
    
    	if ( ! empty( $products ) ) {
    
    		foreach ( $products as $product ) { 
    
    			setup_postdata( $GLOBALS['post'] = $product );
    			get_template_part( 'content', 'products' );
    
    		}
    
    		wp_reset_postdata();
    
    	}
    	?>
    
    </div>

    content-products.php

    $prod_images = get_post_meta( $post->ID, 'cmb2_prod_images', true );
    
    $prod_price = get_post_meta( $post->ID, 'cmb2_prod_price', true );
    
    ?>
    
    <div class="col-xs-12 col-sm-6 col-md-4 product-main wow fadeInUp">
    
    	<figure itemscope itemtype="https://schema.org/Product" class="product-item relative">
    
    		<div class="product-display">
    
    			<div class="list-pic">
    
    				<a href="<?php the_permalink(); ?>">
    
    					<?php
    
    					foreach ($prod_images as $key => $value) {
    
    						echo wp_get_attachment_image( $key, 'prod-list', 'itemprop = image' );
    
    						continue;
    
    					}
    
    					?>
    
    				</a>
    
    			</div>
    
    			<div class="view-detail"><a href="<?php the_permalink(); ?>">View Detail</a></div>
    
    		</div>
    
    		<figcaption class="relative">
    
    			<div class="pro-list-title" >
    
    				<h3 itemprop="name">
    
    				<a href="#"><?php the_title(); ?></a>
    
    				</h3>
    
    			</div>
    
    			<div itemprop="offers" itemscope itemtype="https://schema.org/Offer" class="pro-list-rates">
    
    				<div class="pro-list-rates-new">
    
    					<span  itemprop="priceCurrency">
    
    						<i class="fa fa-inr"></i>
    
    					</span> 
    
    					<span itemprop="price"><?php echo $prod_price; ?></span>
    
    				</div>
    
    			</div>
    
    			<div class="add-container">
    
    				<?php vg_after_entry(); ?>
    
    			</div>
    
    		</figcaption>
    
    	</figure>
    
    </div>

    https://www.ads-software.com/plugins/jetpack/

Viewing 1 replies (of 1 total)
  • Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    I’d suggest a few things that may help:

    • Instead of using a separate function (vg_get_prod_arch_posts) to build your custom query, include these parameters inside loop_p_arch_infinite_scroll_render. Instead of using get_posts, use WP_Query and query conditionals to build your custom query. Most of this is explained here:
      https://codex.www.ads-software.com/Class_Reference/WP_Query
    • Since you’ll have a query that is controlled from one function, you can use a similar structure for all the template parts. That means that you won’t need to include parameters to control the query in archive-products.php.

    Let me know how this goes!

Viewing 1 replies (of 1 total)
  • The topic ‘Infinite Scroll repeating Posts on first run’ is closed to new replies.