Hi
I’m displaying a list of staff members on a page. I’m using a repeater field with 4 sub fields to store the data. (Photo, Name, Description, Level)
This is my code which works fine…
<ul>
<?php
while( the_repeater_field(thp_coach) ) { ?>
<li class="thp-member">
<img src="<?php the_sub_field('photo'); ?>">
<h4><?php the_sub_field('name'); ?></h4>
<p><?php the_sub_field('description'); ?></p>
</li>
<?php }
?>
</ul>
The 4th sub field contains a dropdown list with three values (Bronze, Silver and Gold)
I need to apply class to the <li>
element depending on the value selected in the sub field ‘level’
Any idea how to do this?
I guess I need some kind of ‘if statement’
If the sub_field contains bronze then do this….
Thanks in advance
Brad
Hi Brad, if the values in the “description” dropdown already match your CSS classes (for ease, it would be good if they did), then can you just do something like this:
<ul>
<?php
while( the_repeater_field(thp_coach) ) {
?>
<li class=βthp-member <?php the_sub_field('description'); ?>β>
<img src=β<?php the_sub_field('photo'); ? />β>
<h4><?php the_sub_field('name'); ?></h4>
<p><?php the_sub_field('description'); ?></p>
</li>
<?php } ?>
</ul>
Basically just adding the “description” dropdown value as a class to the <li>
.
You’d then just end up with something like:
<li class="thp-member gold"></li>
No ‘if’ statement required π
wickywills – YOU ARE A LEGEND!
Sometimes it’s the simple things in life eh?
Thank you so much π