Wrap every 12 elements/rows in Advanced Custom Fields Repeater

I’ve been trying (with little success) to wrap every 12 rows (.client-item) outputted by Advance Custom Fields Repeater field with an < li >.

Any help is appreciated!

Read More

Below is the basic code:

    <?php 

    if( have_rows('clients') ): ?>



<?php while( have_rows('clients') ): the_row(); 

    // vars
    $logo = get_sub_field('client_logo');
    $project = get_sub_field('project_image');
    $link = get_sub_field('cleint_link');
    $clientName = get_sub_field('client_name');
    $contracted = get_sub_field('bartle_work');

    ?>

    <?php if($counter % 12 === 0) :    echo '<li>'; endif; ?> 

    <div class="clearfix client-item">


          <div class="feature"> <?php if( $contracted ): ?>
            <div class="asterix"></div>
        <?php endif; ?>
        <?php if( $link ): ?>
            <a href="<?php echo $link; ?>" target="_blank">
        <?php endif; ?>
        <div class="image-frame">




       <img src="<?php echo $logo['url']; ?>" alt="<?php echo $image['alt'] ?>" /></div>
        <p class="client-name"> <?php echo $clientName; ?></p>
        <?php if( $link ): ?>
            </a>
        <?php endif; ?>


        </div>


     <?php $counter++; if($counter % 12 === 0) :  echo '<li>'; endif; ?> 

<?php endwhile; ?>

Related posts

Leave a Reply

1 comment

  1. Check the modulus operator. Here is a demo code on how to use it:

    $counter = 0;
    foreach ($elems as $elem) {
        $counter++;
        if ($counter % 12 === 0) {
        //close and re-open
        }
    }