Hi all, Just wondering what the easiest way to add the a class is to the very first row of repeater loop. Use the repeaters within the bootstrap tabs
I know there’s the example code to only get the first row from the repeater, but I want the whole loop to run through and just add a class. See code below :
<ul class="menu-tabs" role="tablist">
<?php if( have_rows('rainbow') ): while ( have_rows('rainbow') ) : the_row(); ?>
<li role="presentation" /*add class="active" here */>
<a href="#<?php the_sub_field('colour_name'); ?>"
aria-controls="<?php the_sub_field('colour_name'); ?>"
role="tab"
data-toggle="tab">
<?php the_sub_field('colour_name'); ?></a>
</li>
<?php endwhile;?>
<?php endif; ?>
</ul>
Add a counter and output the class if the counter is 0 (zero)
<ul class="menu-tabs" role="tablist">
<?php
if( have_rows('rainbow') ):
$count = 0;
while ( have_rows('rainbow') ) :
the_row();
?>
<li role="presentation"<?php
if (!$count) {
?> class="active"<?php
}
?>><a href="#<?php the_sub_field('colour_name'); ?>"
aria-controls="<?php the_sub_field('colour_name'); ?>"
role="tab"
data-toggle="tab"><?php the_sub_field('colour_name'); ?></a>
</li>
<?php
$count++;
endwhile;
endif;
?>
</ul>