Hi everyone,
Is there a way to display a value unique to each flexible content item so that I can use that value in CSS?
I have a flexible content repeating multiple Wysiwyg containers on a single page. I need to isolate each one with a unique class tag that will not be repeated but is permanent so it CSS can be applied to it.
something like uniqid()
but static.
I solved the problem by creating a php counter http://stackoverflow.com/questions/11869142/how-can-i-make-a-php-counter
column-block-# where # is 1, 2, 3, 4 etc. until the repeat ends. see code below.
// check if the nested repeater field has rows of data
if( have_rows('column_repeater') ):
echo '<ul class="small-block-grid-' . $number_columns . '">';
// loop through the rows of data
while ( have_rows('column_repeater') ) : the_row();
if (empty($counter)){
$counter = 'column-block-' . 1;
}else{
$counter++;
}
$content = get_sub_field ('column_content');
echo '<li><div class="' . $counter . '">' . $content . '</div></li>';
endwhile;
echo '</ul>';
endif;