Jae*_*Lee 1 wordpress advanced-custom-fields
I\xe2\x80\x99m 尝试仅将图库字段中的一张图像显示为缩略图,当查看者单击它时,会弹出一个 fancybox 幻灯片。
\n\n这是我到目前为止所拥有的:
\n\n<?php \n $images = get_field(\'gallery\'); \n $image_1 = $images[0]; \n ?> \n\n <img src="<?php echo $image_1; ?>" /> \nRun Code Online (Sandbox Code Playgroud)\n\n但 HTML 显示这个\xe2\x80\xa6
\n\n<img src="Array">\nRun Code Online (Sandbox Code Playgroud)\n\n请指教。
\n你说你改变了代码,但这有帮助吗?如果是这样,您应该将您的答案标记为“已接受”,以便可以关闭问题。
如果没有,请尝试此操作,假设您将该字段用作图像对象(在创建图像字段时选择):
<?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; ?>
Run Code Online (Sandbox Code Playgroud)
记住 ['value'] 周围的 ' 或 "
| 归档时间: |
|
| 查看次数: |
16291 次 |
| 最近记录: |