Home › Forums › Front-end Issues › Image Class displays regardless of image being empty
I need some syntax help or something…here is the gist.
I have 4 items in play.
Box 1 Content
Box 1 Image
Box 2 Content
Box 2 Image
What I have the need for is:
If there is no content in one of the boxes, change the class to be full width.
If both boxes have content, they are to be in two columns.
If the box has an image, display the class around the image as well as the image.
If the box doesn’t have an image, don’t display the class surrounding the null-image.
Here is the code I have, but for some reason it still puts in the class for the image. Everything else is working correctly.
<?php if(get_field('box_1') and ('box_2')): ?>
<div class="wdg-box-row">
<?php if(get_field('box_1') and ('box_1_image')): ?>
<?php if(get_field('box_1')) { echo '<div class="wdg-box"><div class="wdg-box-image"><img src="' . get_field('box_1_image') . '" /></div>' . get_field('box_1') . '</div>'; } ?>
<?php else: ?>
<?php if(get_field('box_1')) { echo '<div class="wdg-box">' . get_field('box_1') . '</div>'; } ?>
<?php endif; ?>
<?php if(get_field('box_2') and ('box_2_image')): ?>
<?php if(get_field('box_2')) { echo '<div class="wdg-box"><div class="wdg-box-image"><img src="' . get_field('box_2_image') . '" /></div>' . get_field('box_2') . '</div>'; } ?>
<?php else: ?>
<?php if(get_field('box_2')) { echo '<div class="wdg-box">' . get_field('box_2') . '</div>'; } ?>
<?php endif; ?>
</div>
<?php else: ?>
<div class="wdg-box-row">
<?php if(get_field('box_1') and ('box_1_image')): ?>
<?php if(get_field('box_1')) { echo '<div class="wdg-box-full"><div class="wdg-box-image"><img src="' . get_field('box_1_image') . '" /></div>' . get_field('box_1') . '</div>'; } ?>
<?php else: ?>
<?php if(get_field('box_1')) { echo '<div class="wdg-box-full">' . get_field('box_1') . '</div>'; } ?>
<?php endif; ?>
<?php if(get_field('box_2') and ('box_2_image')): ?>
<?php if(get_field('box_2')) { echo '<div class="wdg-box-full"><div class="wdg-box-image"><img src="' . get_field('box_2_image') . '" /></div>' . get_field('box_2') . '</div>'; } ?>
<?php else: ?>
<?php if(get_field('box_2')) { echo '<div class="wdg-box-full">' . get_field('box_2') . '</div>'; } ?>
<?php endif; ?>
</div>
<?php endif; ?>
The topic ‘Image Class displays regardless of image being empty’ 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.