• Resolved jjf21

    (@jjf21)


    I have my posts set up in a loop on my front page so that it’s one large post in the first row, 3 small posts in second row, 3 small posts in third row, etc. How would I add this to the post repeater template?

    my front-page.php
    <?php
    /*
    * Template Name:
    */

    get_header();
    get_template_part (‘inc/carousel’);

    $the_query = new WP_Query( [
    ‘posts_per_page’ => 14,
    ‘paged’ => get_query_var(‘paged’, 1)
    ] );

    if ( $the_query->have_posts() ) { ?>
    <div id=”ajax-load”>
    <?php
    $i = 0;
    while ( $the_query->have_posts() ) { $the_query->the_post();

    if ( $i % 7 === 0 ) { // Large post: on the first iteration and every 7th post after… ?>
    <article <?php post_class( ‘col-sm-12 col-md-12’ ); ?>>
    <div class=”large-front-container”>
    <?php the_post_thumbnail(‘full’, array(‘class’ => ‘large-front-thumbnail’)); ?>
    </div>
    <h2>“><?php the_title(); ?></h2>
    <p class=”front-page-post-excerpt”><?php echo get_the_excerpt(); ?></p>
    “>Read more
    <?php get_template_part (‘front-page-shop’); ?>
    <?php get_template_part( ‘share-buttons’ ); ?>
    <div class=”front-comments”><?php comments_popup_link (‘0’, ‘1’, ‘%’, ‘comment-count’, ‘none’); ?></div>
    </article><?php

    } else { // Small posts ?>
    <article <?php post_class( ‘col-sm-6 col-md-4’ ); ?>>
    <div class=”front-thumbnail-image”><?php the_post_thumbnail(‘full’, array(‘class’ => ‘medium-front-thumbnail’)); ?></div>
    “><?php the_title(); ?>
    <p class=”front-page-post-excerpt”><?php echo get_the_excerpt(); ?></p>
    “>Read more
    <?php get_template_part (‘front-page-shop’); ?>
    <?php get_template_part( ‘share-buttons’ ); ?>
    <div class=”front-comments”><?php comments_popup_link (‘0’, ‘1’, ‘%’, ‘comment-count’, ‘none’); ?></div>
    </article>
    <?php
    }
    $i++;
    }?>
    </div>
    <?php if(get_query_var(‘paged’) < $the_query->max_num_pages) {
    echo do_shortcode( ‘[ajax_load_more id=”ajax-load” post_type=”post” posts_per_page=”14″ pause=”true” scroll=”false” button_label=”LOAD POSTS”]’ );
    }
    }
    elseif (!get_query_var(‘paged’) || get_query_var(‘paged’) == ‘1’) {
    echo ‘<p>Sorry, no posts matched your criteria.</p>’;
    }
    wp_reset_postdata();
    get_footer();

    what I tried adding to the repeater template…
    <div id=”ajax-load”>
    <?php
    $i = 0;
    while ( $the_query->have_posts() ) { $the_query->the_post();

    if ( $i % 7 === 0 ) { // Large post: on the first iteration and every 7th post after… ?>
    <article <?php post_class( ‘col-sm-12 col-md-12’ ); ?>>
    <div class=”large-front-container”>
    <?php the_post_thumbnail(‘full’, array(‘class’ => ‘large-front-thumbnail’)); ?>
    </div>
    <h2>“><?php the_title(); ?></h2>
    <p class=”front-page-post-excerpt”><?php echo get_the_excerpt(); ?></p>
    <div class=”front-post-info”>
    “>Read more
    <?php get_template_part (‘front-page-shop’); ?>
    <?php get_template_part( ‘share-buttons’ ); ?>
    <div class=”front-comments”><?php comments_popup_link (‘0’, ‘1’, ‘%’, ‘comment-count’, ‘none’); ?></div>
    </article><?php

    } else { // Small posts ?>
    <article <?php post_class( ‘col-sm-6 col-md-4’ ); ?>>
    <div class=”front-thumbnail-image”><?php the_post_thumbnail(‘full’, array(‘class’ => ‘medium-front-thumbnail’)); ?></div>
    “><?php the_title(); ?>
    <p class=”front-page-post-excerpt”><?php echo get_the_excerpt(); ?></p>
    “>Read more
    <?php get_template_part (‘front-page-shop’); ?>
    <?php get_template_part( ‘share-buttons’ ); ?>
    <div class=”front-comments”><?php comments_popup_link (‘0’, ‘1’, ‘%’, ‘comment-count’, ‘none’); ?></div>
    </article>
    <?php
    }
    $i++;
    }?>
    </div>

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter jjf21

    (@jjf21)

    Here is a link to my front-page.php file. As you can see I have 14 posts per page. 1 in a row, 3 in a row, 3 in a row. I just want to add the load more button after every 14 posts. However, I don’t know how I could achieve this. I would appreciate any help!

    https://www.dropbox.com/s/ax15kaa8msvunoe/front-page.php?dl=0

    Plugin Author Darren Cooney

    (@dcooney)

    Hi ,
    You can access the current post number using Ajax Load More variables – this will help you build your repeater to match what you currently have.
    https://connekthq.com/plugins/ajax-load-more/docs/variables/

    So,

    if ( $alm_item % 7 === 0 ) {  // Large posts
    
    } else {  // Small posts
    
    }

    Cheers,

    Thread Starter jjf21

    (@jjf21)

    I’ve attached my new repeater template, but it is still not working.

    https://www.dropbox.com/s/95pcuhivp3sfvuw/default.php?dl=0

    
    <?php
    /*
     * Template Name:
     */
    
    $the_query = new WP_Query( [
        'posts_per_page' => 14,
        'paged' => get_query_var('paged', 1)
    ] );
    
    if ( $the_query->have_posts() ) { ?>
        <div id="ajax-load">
        <?php
        $i = 0;
        while ( $the_query->have_posts() ) { $the_query->the_post();
    
            if ( $alm_item % 7 === 0 ) {  // Large posts ?>
            <article <?php post_class( 'col-sm-12 col-md-12' ); ?>>
                <div class="large-front-container">
    <?php the_post_thumbnail('full', array('class' => 'large-front-thumbnail')); ?>
                    </div>
                <h2><a class="post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                <p class="front-page-post-excerpt"><?php echo get_the_excerpt(); ?></p>
                <a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
                    <?php get_template_part ('front-page-shop'); ?>
                                     <?php get_template_part( 'share-buttons' ); ?>
                    <div class="front-comments"><?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?></div>
                </article><?php
    
            } else {  // Small posts ?>
                <article <?php post_class( 'col-sm-6 col-md-4' ); ?>>
                    <div class="front-thumbnail-image"><?php the_post_thumbnail('full', array('class' => 'medium-front-thumbnail')); ?></div>
                    <a class="front-page-post-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                    <p class="front-page-post-excerpt"><?php echo get_the_excerpt(); ?></p>
                    <a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
                    <?php get_template_part ('front-page-shop'); ?>
                                     <?php get_template_part( 'share-buttons' ); ?>
                    <div class="front-comments"><?php comments_popup_link ('0', '1', '%', 'comment-count', 'none'); ?></div>
                </article>
                <?php
            }
            $i++;
        }?>
        </div>
        <?php if(get_query_var('paged') < $the_query->max_num_pages) {
        }
    }
    elseif (!get_query_var('paged') || get_query_var('paged') == '1') {
        echo '<p>Sorry, no posts matched your criteria.</p>';
    }
    wp_reset_postdata();
    
    Plugin Author Darren Cooney

    (@dcooney)

    You don’t neee the Query. Ajax Load More takes care of the Query.

    You need to use the shortcode to implement the plugin.

    Please check out the examples on the website and look at the help page inside the plugin.
    https://connekthq.com/plugins/ajax-load-more/examples/

    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to add post loop to repeater template’ is closed to new replies.