隐藏空字段
我试图隐藏以下内容中的空字段:
<?php
$events = get_group('Gallery');
foreach($events as $event){ ?>
<a href="<?php echo $event['gallery_image_1'][1]['o']; ?>"><img src="<?php echo $event['gallery_image_1'][1]['t']; ?>" /></a>
<a href="<?php echo $event['gallery_image_2'][1]['o']; ?>"><img src="<?php echo $event['gallery_image_2'][1]['t']; ?>" /></a>
<a href="<?php echo $event['gallery_image_3'][1]['o']; ?>"><img src="<?php echo $event['gallery_image_3'][1]['t']; ?>" /></a>
<?php }?>
目前,所有字段都会显示是否确实存在图像。我已经尝试了多种解决方案,但没有运气,所以任何帮助将不胜感激,
非常感谢
I'm trying to hide the empty fields in the following:
<?php
$events = get_group('Gallery');
foreach($events as $event){ ?>
<a href="<?php echo $event['gallery_image_1'][1]['o']; ?>"><img src="<?php echo $event['gallery_image_1'][1]['t']; ?>" /></a>
<a href="<?php echo $event['gallery_image_2'][1]['o']; ?>"><img src="<?php echo $event['gallery_image_2'][1]['t']; ?>" /></a>
<a href="<?php echo $event['gallery_image_3'][1]['o']; ?>"><img src="<?php echo $event['gallery_image_3'][1]['t']; ?>" /></a>
<?php }?>
At the moment all fields display whether or not there is actually an image there. I've tried numerous solutions but no luck so any help would be much appreciated
many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
array_key_exists
:Use
array_key_exists
:回显 who 链接,而不仅仅是 url 和路径。这样,如果没有图像,您可以选择不显示链接。
echo the who link instead of just the url and path. That way, you can choose not to display the link if there is no image.
也许这很有帮助,但我不确定,因为你的问题非常广泛:
Maybe this is helpful but I'm unsure as your question was very broad: