Support

Account

Home Forums Add-ons Repeater Field Separating last row from others Reply To: Separating last row from others

  • Beautiful, I knew it was something simple that I was missing. I took your example and tweaked it so that if the user only inputs a single color, it’ll fall back to background-color rather than background-image for the gradient. Thanks for your help! Much appreciated! 🙂

    
    <?php 
    if( have_rows('bike_listing-color') ) { //Bike color bar
    $colors = array(); 
    ?>
    <div class="colorbar" id="colorbar-<?php the_ID(); ?>"></div> 
    <?php 
    while (have_rows('bike_listing-color')) {
      the_row();
      $colors[] = get_sub_field('color');
      $count = count($colors);
    } 
    if ( $count > 1 ) { ?>
    <style>
      #colorbar-<?php the_ID(); ?>{
        background-image: linear-gradient(to right, <?php echo implode(', ', $colors); ?>);
      }
    </style>
    <?php } else { ?>
    <style>
      #colorbar-<?php the_ID(); ?>{
        background-color: <?php echo implode($colors); ?>;
      }
    </style>
    <?php } ?>
    <?php } // End if have_rows ?>