Support

Account

Forum Replies Created

  • +1 for me on this too. It’s definitely functionality that would make life a little easier. Thanks! 🙂

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