• Resolved jjean

    (@jjean)


    I’ve been going through codes on how to create loops without duplications for the repeater template, but I can’t seem to figure it out. Everything leads to duplicate posts when I click “Load More”

    Does the repeater template detect arrays from the index/home page?

    This is how my coding looks like so far. Is there something that I’m missing? Any leads would be helpful.

    <!– HOME/INDEX PAGE – SHOWS FIRST & MAIN IMAGE / FIRST LOOP –>
    <?php
    $do_not_duplicate = array();
    $my_query = new WP_Query(‘showposts=1’);
    while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate[] = $post->ID;
    ?>
    <div class=”post-<?php the_ID(); ?> static-image-wrapper”>
    <?php echo get_the_image_link(array(‘image’,’My Image’),’medium’); ?>
    <div class=”title-overlay”><h2>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_title() ?></h2>
    <!– <p class=”postmetadata”><?php the_time(‘M d, Y’) ?></p> –>
    </div>
    </div>
    <?php endwhile; ?>

    <!– HOME/INDEX PAGE – SHOWS TWO COLUMN THUMBNAILS WITHOUT DUPLICATION / SECOND LOOP –>
    <?php
    $args = array (
    ‘post_type’ => ‘post’,
    ‘posts_per_page’ => ’14’,
    ‘post__not_in’ => $do_not_duplicate
    );

    $i = 0;
    $my_query = new WP_Query($args);
    if ($my_query -> have_posts()) : while ($my_query -> have_posts()) : $my_query -> the_post();
    $do_not_duplicate[] = $post->ID;
    if (!in_array( $post->ID, $do_not_duplicate )) continue; update_post_caches($posts); $i++;
    ?>
    <div class=”span-12 post-<?php the_ID(); ?><?php if ($i == 2) { ?> last<?php } ?>”>
    <h1 class=”title-header”>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_title() ?></h1>
    <div class=”post-format-content”>
    <div class=”featured-image”><?php echo get_the_image_link(array(‘thumbnail’,’thumbnail-news’),’thumbnail’); ?></div>
    <div class=”content-wrap”><h1 class=”entry-title”><?php the_title(); ?></h1></div>
    </div>
    <p class=”postmetadata”></p>
    </div>
    <?php if ($i == 2) { ?>
    <div class=”archive-stack clear”></div>
    <?php $i = 0; } ?>
    <?php endwhile; endif; ?>

    <!– REPEATER TEMPLATE –>
    Same code as Second Loop

    https://www.ads-software.com/plugins/ajax-load-more/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Darren Cooney

    (@dcooney)

    Hi jjean,
    Sorry, I’m fully understanding the issue.

    Are those queries the code you are placing in the repeater templates?

    Thread Starter jjean

    (@jjean)

    Hi,

    Yes, the code for the “Second Loop” is being used as the repeater template.

    <?php
    $args = array (
    ‘post_type’ => ‘post’,
    ‘posts_per_page’ => ’14’,
    ‘post__not_in’ => $do_not_duplicate
    );

    $i = 0;
    $my_query = new WP_Query($args);
    if ($my_query -> have_posts()) : while ($my_query -> have_posts()) : $my_query -> the_post();
    $do_not_duplicate[] = $post->ID;
    if (!in_array( $post->ID, $do_not_duplicate )) continue; update_post_caches($posts); $i++;
    ?>
    <div class=”span-12 post-<?php the_ID(); ?><?php if ($i == 2) { ?> last<?php } ?>”>
    <h1 class=”title-header”>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_title() ?></h1>
    <div class=”post-format-content”>
    <div class=”featured-image”><?php echo get_the_image_link(array(‘thumbnail’,’thumbnail-news’),’thumbnail’); ?></div>
    <div class=”content-wrap”><h1 class=”entry-title”><?php the_title(); ?></h1></div>
    </div>
    <p class=”postmetadata”></p>
    </div>
    <?php if ($i == 2) { ?>
    <div class=”archive-stack clear”></div>
    <?php $i = 0; } ?>
    <?php endwhile; endif; ?>

    Plugin Author Darren Cooney

    (@dcooney)

    Hi jjean,
    Well you wouldn’t want to add your own loop inside the repeater templates. That is what Ajax Load More is for. It handles the loop and you just worry about the code template that repeaters over as the loop is run.

    For example:
    <li><?php if ( has_post_thumbnail() ) { the_post_thumbnail(array(100,100));}?><h3><a href="#" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3><p class="entry-meta"><?php the_time("F d, Y"); ?></p><?php echo excerpt(50); ?></li>

    Thread Starter jjean

    (@jjean)

    Thanks.

    I think the issue I’m having the most is duplicate posts.

    I start off with 15 thumbnail posts on the main screen. How do I have Ajax Load More start on the 16th post without duplicating posts?

    I tried “$query = new WP_Query( ‘offset=15’ );”, but the repeater template loops back to the 15th post on every load.

    Plugin Author Darren Cooney

    (@dcooney)

    Why are you using WP_Query in your repeater?

    Ajax Load More is the WP_Query, use the shortcode builder and offset the posts by 15.

    Have you been using the builder?

    cheers,
    -d

    Thread Starter jjean

    (@jjean)

    Ahh…finally got it. Didn’t see the offset parameter for Load More.

    Also, was able to get two columns by simplifying the repeater to:

    <?php $i ++; ?>
    <div class=”span-12 post-<?php the_ID(); ?><?php if ($i == 2) { ?> last<?php } ?>”>
    <h1 class=”title-header”>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_title() ?></h1>
    <div class=”post-format-content”>
    <div class=”featured-image”><?php echo get_the_image_link(array(‘thumbnail’,’thumbnail-news’),’thumbnail’); ?></div>
    <div class=”content-wrap”><h1 class=”entry-title”><?php the_title(); ?></h1></div>
    </div>
    <p class=”postmetadata”></p>
    </div>
    <?php if ($i == 2) { ?>
    <div class=”archive-stack clear”></div>
    <?php $i =0; } ?>

    Thanks!

    Plugin Author Darren Cooney

    (@dcooney)

    Ok great!
    Closing ticket.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Repeater Template’ is closed to new replies.