• Hi!

    I have a custom page-template and in that template I am running two loops.
    The first one showing the latest 6 posts with featured image, and then after that the rest of the posts showing the title.

    Everything is working as I want to, execpt for when it comes to adding a infinite scroll to this page. I get it to work, but the posts gets repeated down the page. I want the first 6 posts to stay at the top showing the thumbnails, and then the list of posts showing only the title grows as I scroll down.

    I have tried the do not duplicate link, but cant get that to work.

    Here is the code I use, ( sorry if the code is messy, im a newbie 🙁 )

    <?php
    $temp = $wp_query;
    $wp_query = null;
    $wp_query = new WP_Query();
    $wp_query->query('showposts=6&post_type=post'.'&paged='.$paged); 
    
    while ($wp_query->have_posts()) : $wp_query->the_post();
    ?>
    <?php get_template_part('templates/featured'); ?>
    
    <?php endwhile; ?>
    
    <?php
    // Second query arguments.
    $args2 = array(
      'offset' => '6',
      'post_type' => 'post',
      );
    
    $query2 = new WP_Query( $args2 );
    if ( $query2->have_posts() ) {
      echo '<ul class="more-posts">';
      while ( $query2->have_posts() ) {
        $query2->the_post();
        ?>
    
        <?php get_template_part('templates/content'); ?>
        <?php
      }
      echo '</ul>';
    }
    // Restore original post data.
    wp_reset_postdata();
    ?>
    <?php
    $wp_query = null;
      $wp_query = $temp;  // Reset
      ?>

    Hope someone can help me out!

The topic ‘Infinite Scroll repeats my posts’ is closed to new replies.