Support

Account

Home Forums Add-ons Repeater Field Add class to first row of repeater

Solved

Add class to first row of repeater

  • 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>
    
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Add class to first row of repeater’ is closed to new replies.