I'm trying to create a two column element using ACF repeater fields. The only thing is I'm trying to alternate this so that the content in the two columns switches left/right depending on the row being even or odd.
The output will look something like:
Row 1: Image (left column), Description (right column)
Row 2: Description (left column), Image (right column)
Row 3: Image (left column), Description (right column)
Row 4: Description (left column), Image (right column)
.
.
.
This is how I looped it:
<section id="projects" class="container specific-margin-1">
<div class="row specific-padding-4">
<div class="container col-lg-12">
<center><h2>FEATURED PROJECTS</h2></center>
</div><!-- col-lg-12 -->
</div><!-- row -->
<!-- Repeater -->
<div class="row">
<?php $row = 0; //<-- set your counter to 0
if(get_field('featured_projects')): ?>
<?php while(has_sub_field('featured_projects')): ?>
<?php if ($counter % 2 === 0) :?>
<div class="row">
<!-- right column -->
<div class="col-lg-9 col-md-8 col-sm-6">
<img src="<?php the_sub_field('project_image'); ?>" />
</div>
<div class="col-lg-3 col-md-4 col-sm-6">
<?php the_sub_field('project_details'); ?>
</div><!-- right column -->
</div>
<?php else: ?>
<div class="row">
<!-- left column -->
<div class="col-lg-3 col-md-4 col-sm-6">
<?php the_sub_field('project_details'); ?>
</div>
<div class="col-lg-9 col-md-8 col-sm-6">
<img src="<?php the_sub_field('project_image'); ?>" />
</div><!-- left column -->
</div>
<?php endif; ?>
<?php $row++; endwhile; ?>
<?php endif; ?>
</div><!-- Repeater -->
</section>