Infinite Scroll repeating Posts on first run
-
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>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Infinite Scroll repeating Posts on first run’ is closed to new replies.