高级自定义字段获取子字段图像 [英] Advanced Custom Fields get sub field image
问题描述
我在 ACF 中有一个子字段,名为imgcolumn_1".
I have a sub field in ACF, named 'imgcolumn_1'.
这被设置为一个图像,并允许用户添加一个图像.
This is set to be an image, and allows the user to add an image.
现在,在 PHP 中,我试图检索用户添加的输入.
Now, when in PHP, I am trying to retrieve the input the user adds.
例如,我在 AFC 中有另一个名为 column_1 的子字段,我使用
For example, I have another sub field in AFC called column_1, which I retrieve using
<?php the_sub_field('column_1');?>
还有其他方法可以检索图像吗?我正在尝试以下操作:
Is there another way to retrieve the image? I am trying the below:
<img src="<?php the_sub_field('imgcolumn_1'); ?>" />
但这不显示图像,而是显示以下内容:
But this doesnt display the image, but instead shows the following:
当我检查这个时,我可以看到 URL 在那里,但它被其他数字包围了?
When I inspect this, I can see the URL is there, but it is surrounded by other numbers?
任何帮助都会很棒.
推荐答案
你是否返回了 URL、Array 或 ID场地?
Do you return a URL an Array or an ID from your field?
对我来说看起来像一个数组,所以:解决方案1:
looks like an array to me so: Solution 1:
$image = get_sub_field('imgcolumn_1');
<img src="<?php echo $image['url'];?>" />
解决方案 2(如果 id):
Solution 2 (if id):
$image = get_sub_field('imgcolumn_1');
<img src="<?php echo get_permalink($image);?>" />
解决方案 3(如果 url):
Solution 3 (if url):
$image = get_sub_field('imgcolumn_1');
<img src="<?php echo $image;?>" />
这篇关于高级自定义字段获取子字段图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!