如何隐藏“图像"自定义字段如果为空 [英] How to hide "image" custom field if empty
本文介绍了如何隐藏“图像"自定义字段如果为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个自定义字段的无序列表,如果它们为空,我希望隐藏它们.对于文本自定义字段,我使用了代码:
I created an unordered list of custom fields and I wish to hide them if they are empty. For text custom fields I used the code:
<?php if (get_field('phone') != '') { ?>
<li><strong>Phone: </strong><?php the_field('phone'); ?></li>
<?php } ?>
但是,我有一个用于图像的自定义字段,如下所示:
However, I have a custom field which is for images, like this:
<li><strong>Logo: </strong><img src="<?php the_field('logo'); ?>"></img></li>
如果没有上传图片,我如何隐藏该字段(显然,上面的代码不起作用)?提前致谢.
How can I hide the field if no image was uploaded (obviously, the above code won't work)? Thanks in advance.
推荐答案
假设 the_field('logo')
将返回一个假值,如果没有图像
Assuming the_field('logo')
will return a falsy value if there are no images
if (the_field('logo')) {
?>
<li><strong>Logo: </strong><img src="<?php the_field('logo'); ?>"></img></li>
<?php
}
这篇关于如何隐藏“图像"自定义字段如果为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文