1

我试图仅将我的画廊字段中的一个图像显示为缩略图,当观众单击它时,会弹出一个精美的幻灯片。

这是我到目前为止所拥有的:

<?php 
    $images = get_field('gallery'); 
    $image_1 = $images[0]; 
    ?>    

    <img src="<?php echo $image_1; ?>" />    

但是 HTML 显示了这一点……</p>

<img src="Array">

请指教。

4

2 回答 2

4

您说您更改了代码,但这有帮助吗?如果是这样,您应该将您的答案标记为“已接受”,以便可以关闭问题。

如果不是,那么试试这个,假设您将该字段用作图像对象(在创建图像字段时选择):

<?php 
$images = get_field('gallery'); // get gallery
$image  = $images[0]; // get first image in the gallery [1] for second, [2] for third, and so on.

if( $image ) : // only show the image if it exists ?> 
    <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>

记住 ['value'] 周围的 ' 或 "

于 2014-02-27T21:53:51.597 回答
3

我把代码改成了这个;

        <?php 
        $images = get_field('gallery'); 
        $image_1 = $images[0]; 
        ?>    

        <img src="<?php echo $image_1[url]; ?>" />  
于 2014-02-20T00:11:19.850 回答