【问题标题】:Return first image in gallery array of Pods Framework in WordPress返回 WordPress 中 Pods 框架图库数组中的第一张图片
【发布时间】:2018-06-01 20:31:26
【问题描述】:

我在 Pod 中有一个名为“图库”的多维数组,它只包含照片。我只想在我的 WordPress 页面中返回该数组的第一张图片,但是正在显示该数组中的所有图片。这是我目前正在使用的代码:

<?php foreach($vehiclepods->field('gallery', true) as $picture) { ?> <img src="<?php echo $picture['guid'];?>" alt="image" /></a> <?php } ?>

我做错了什么,如何才能让数组中的第一个图像显示出来?

screenshot of output

Full PasteBin of the index file is here.

【问题讨论】:

    标签: php arrays wordpress loops podscms


    【解决方案1】:

    好吧,您的图像输出包含在 foreach 中。因此,如果您只想使用第一个图像,您将获得每张图像

    $gallery = $vehiclepods->field('gallery', true);
    
    <img src="<?php echo $gallery[0]['guid'];?>" alt="image" />
    

    这样,画廊是一个数组,您将获得数组中的第一个图像 src。 [0][guid]

    【讨论】:

    • 谢谢!这是完美的,并为指出我的错误而欢呼。
    猜你喜欢
    • 2011-11-08
    • 1970-01-01
    • 1970-01-01
    • 2013-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-04
    • 1970-01-01
    相关资源
    最近更新 更多