隐藏空字段

发布于 2024-11-16 08:43:19 字数 689 浏览 1 评论 0原文

我试图隐藏以下内容中的空字段:

<?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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

猫瑾少女 2024-11-23 08:43:19

使用 array_key_exists

if (array_key_exists('gallery_image_1', $event) { ?>
    <a href="<?php echo $event['gallery_image_1'][1]['o']; ?>"><img src="<?php echo     $event['gallery_image_1'][1]['t']; ?>" /></a>
<?php }

Use array_key_exists:

if (array_key_exists('gallery_image_1', $event) { ?>
    <a href="<?php echo $event['gallery_image_1'][1]['o']; ?>"><img src="<?php echo     $event['gallery_image_1'][1]['t']; ?>" /></a>
<?php }
请别遗忘我 2024-11-23 08:43:19

回显 who 链接,而不仅仅是 url 和路径。这样,如果没有图像,您可以选择不显示链接。

if (!empty($event['gallery_image_1'][1]['t'])) {
    echo "<a href=\"" . $event['gallery_image_1'][1]['o'] . "\"><img src=\"" . $event['gallery_image_1'][1]['t'] . "\" /></a>";
}

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.

if (!empty($event['gallery_image_1'][1]['t'])) {
    echo "<a href=\"" . $event['gallery_image_1'][1]['o'] . "\"><img src=\"" . $event['gallery_image_1'][1]['t'] . "\" /></a>";
}
·深蓝 2024-11-23 08:43:19

也许这很有帮助,但我不确定,因为你的问题非常广泛:

<?php 

$events = get_group('Gallery');
foreach($events as $event){ 

  for($i=1;$i<4;$i++) {
    if(empty($event['gallery_image_'.$i])) 
      continue
      ;
    $image = $event['gallery_image_'.$i];
?>

<a href="<?php echo $image[1]['o']; ?>"><img src="<?php echo $image[1]['t']; ?>" /></a>

<?php } }?>

Maybe this is helpful but I'm unsure as your question was very broad:

<?php 

$events = get_group('Gallery');
foreach($events as $event){ 

  for($i=1;$i<4;$i++) {
    if(empty($event['gallery_image_'.$i])) 
      continue
      ;
    $image = $event['gallery_image_'.$i];
?>

<a href="<?php echo $image[1]['o']; ?>"><img src="<?php echo $image[1]['t']; ?>" /></a>

<?php } }?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文