Home › Forums › Front-end Issues › Show ACF only if they exists in a div › Reply To: Show ACF only if they exists in a div
<?php
$fields = get_fields();
if ($fields) {
foreach ($fields as $field => $value) {
if ($value) {
?>
<div>
<h3><?php echo $name; ?></h3>
<?php
switch ($name) {
case 'case':
$src = 'url for this field name';
break;
case 'for':
$src = 'url for this field name';
break;
case 'every':
$src = 'url for this field name';
break;
case 'possible':
$src = 'url for this field name';
break;
case 'field':
$src = 'url for this field name';
break;
case 'name':
$src = 'url for this field name';
break;
default:
// default for all field names not listed above
$src = 'default url';
} // end switch
?>
<img src="<?php echo $src; ?>" />
<p><?php echo $value; ?></p>
</div>
<?php
} // end if $value
} // end foreach field
} // end if fields
?>
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.