Home › Forums › Add-ons › Repeater Field › IF/ELSEIF
Hello, has anyone used an IF/ELSEIF inside of a Repeater….
We’re trying to show either an Icon or an Image within a <figure> tag depending on which the user has selected. This “avatar” is appearing within each card in a repeating list of cards…
<?php
foreach ($section['cards'] as $item => $block) :
?>
<li class="mdl-cell--2--col demo-card-square mdl-card mdl mdl-shadow--2dp" style="background-color: <?=$section['card_background_color']?>">
<aside class="mdl-list--title--subtitle">
<figure class="mdl-list--avatar" style="background-color:<?=$section['avatar_background_color']?>">
<?php if ($block['use_avatar_image_or_icon'] == 'avatar') { ?>
<img src="<?=$block['card_avatar']?>" id="avatar__image"/>
<?php } else if ($block['use_avatar_image_or_icon'] == 'icon') { ?>
<i style="color:<?=$section['icon_color']?>;" class="fa <?=$block['card_icon']?>" ></i>
<?php }?>
</figure>
<?php
endforeach;
?>
I don’t see anything wrong with your code, but I’m not sure what’s not working? What is being shown and how does it differ from what you want?
Hey John, so interestingly neither the <i> or the shows in the source code of a published page. Screenshot of source.
We’ve got “icon” selected in ACF
Actually – I’m not sure myself but it looks like the issue may have cleared up. So maybe it was a caching bug. Sorry about that.
The topic ‘IF/ELSEIF’ is closed to new replies.
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.