[英]ACF not returning image
I am trying to use ACF to put an image on one of my template pages.我正在尝试使用 ACF 将图像放在我的一个模板页面上。 I did a var_dump of my variable and the data is there.
我对我的变量做了一个 var_dump,数据就在那里。 Why is my image not showing up?
为什么我的图片不显示? I tried wrapping it in an tag but that didn't return anything.
我尝试将其包装在标签中,但没有返回任何内容。 Any suggestions?
有什么建议么?
<?php
$first_img = get_field('image_first');
?>
<div class="panel--standard">
<div class="container container__grid">
<div class="container__col">
<h2><?php echo get_field("heading_first"); ?></h2>
<div>
<?php echo get_field($first_img['url']); ?>
</div>
<!-- <p><?php var_dump($first_img['url'])?></p> -->
</div>
<div class="container container__col">
<p><?php echo get_field("content_first"); ?></p>
</div>
</div>
</div>
Advanced Custom Fields can be set to return data in a few ways.高级自定义字段可以设置为以几种方式返回数据。 It looks by your code like this image field is set to return 'Array'.
从您的代码看来,此图像字段设置为返回“数组”。 So the way you're grabbing it, $first_img is an array of your data, with URL being the source of the original, uncropped image.
因此,您获取它的方式是,$first_img 是您的数据数组,其中 URL 是原始未裁剪图像的来源。 What you actually have isn't an 'image' itself - just the data.
你实际拥有的不是“图像”本身——只是数据。
On this line, you're trying to REFETCH the field data, with the URL which isn't correct:在这一行上,您正在尝试使用不正确的 URL 重新获取字段数据:
<?php echo get_field($first_img['url']); ?>
Instead, what you're looking for is something like:相反,您正在寻找的是类似的东西:
<img src="<?php echo $first_img['url']; ?>" alt="<?php echo $first_img['alt']; ?>"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.