Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save johnkvang/f658c3845bef40e1427d1b12305820f4 to your computer and use it in GitHub Desktop.
Save johnkvang/f658c3845bef40e1427d1b12305820f4 to your computer and use it in GitHub Desktop.
Give an ACF Repeater subfield alternating classes, in this case, 'Odds' and 'Evens'. This can be applied to other things as well. Be creative. :)
<?php if ( have_rows( 'acf_repeater_field' ) ) : ?>
<?php $counter = 1 ; ?>
<?php while ( have_rows( 'acf_repeater_field' ) ) : the_row(); ?>
<?php
if ( 0 === $counter % 2 ) {
$class = 'even';
} else {
$class = 'odd';
}
?>
<div class="<?php echo $class;?>">
<?php the_sub_field( 'acf_repeater_subfield' );?>
</div>
<?php $counter++ ; ?>
<?php endwhile; ?>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment