Support

Account

Home Forums Add-ons Repeater Field Unique ID for Repeater Field Reply To: Unique ID for Repeater Field

  • Thanks for this code Elliot, it works just as I wanted. Not sure if you can help with this but I’ve got a related problem.

    I’m creating a list of tabs with the repeater field and using the psuedo-class :checked to give the selected tab a different background colour.

    The problem is that when using the repeater field the last tab rendered is the one selected when the user arrives on the page. What I’d like to happen is the first tab be selected instead.

    My code is below and you can see it in operation here: http://londonsleepcentre.ae/sleep-apnea-osa-treatment-services/mandibular-devices/

    
        <div class="tabs">
          <?php if(get_field('additional_content')): $i = 0; ?>
            <?php while(has_sub_field('additional_content')): $i++; ?>
                <input type="radio" name="tabs" id="tab<?php echo $i; ?>" checked />
                <label for="tab<?php echo $i; ?>" class="<?php the_sub_field('field_label'); ?>"><?php the_sub_field('extra_title'); ?></label>
            <?php endwhile; ?>
          <?php endif; ?> 
          <?php if(get_field('additional_content')): $i = 0; ?>
            <?php while(has_sub_field('additional_content')): $i++; ?>
              <div id="tab-content<?php echo $i; ?>" class="tab-content">
                  <?php the_sub_field('extra_content'); ?>
              </div> <!-- #tab-content1 -->        
            <?php endwhile; ?>
          <?php endif; ?> 
        </div>