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 ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.