[英]Advanced Custom Fields syntax error
I am editing a wordpress theme to add two fields to a slider plugin. 我正在编辑wordpress主题,以将两个字段添加到滑块插件。 I am using advanced custom fields to do this since I don't know PHP too well. 由于我不太了解PHP,因此我正在使用高级自定义字段来执行此操作。
added customheader-img and big-descrip 添加了customheader-img和big-decrip
$videobg_container .= ' <li> <div class="slide-container container text-'.$videobg_alignment.'"> <div class="slide-content page-scroll" style="vertical-align:'.$videobg_vertical_alignment.';"> <div class="customheader-img">$image = get_field('.$custom_header_image.');</div> '.$videobg_description.$videobg_title.$button1.' <div class="big-descrip" <?php the_field( 'Subtext'); ?></div> </div> </div> </li>'; }
The code above spits out a syntax error. 上面的代码吐出语法错误。 If I change the single quotes to double quotes ('Subtext') to ("Subtext") it doesn't error out but the content I add to the custom field doesn't show up. 如果我将单引号更改为双引号('Subtext')更改为(“ Subtext”),则不会出错,但是不会显示我添加到自定义字段中的内容。
Any ideas what I can do here? 有什么想法我可以在这里做什么?
Thanks! 谢谢!
Try this: 尝试这个:
$videobg_container .='
<li>
<div class="slide-container container text-' . $videobg_alignment . '">
<div class="slide-content page-scroll" style="vertical-align:' . $videobg_vertical_alignment . '">
<div class="customheader-img">' . get_field('custom_header_image')['url'] .'</div>
'.$videobg_description.$videobg_title.$button1.'
<div class="big-descrip">'. get_field('Subtext'). '"></div>
</div>
</div>
</li>';
For more info how to query a image ACF field you could read in ACF docs 有关如何查询图像ACF字段的更多信息,您可以在ACF文档中阅读
To get Image field using ACF 使用ACF获取图像字段
$image = get_field('image');
Use print_r($image); 使用print_r($ image); and see to that there are multiple dimensions of the image uploaded and you could display based on the key values of the array // each image contains a custom field called 'link' 并确认上传的图片有多个维度,您可以根据数组的键值进行显示//每个图片都包含一个名为“ link”的自定义字段
$link = get_field('link', $image['ID']);
At last you can have the image as <?php echo $image['url']; ?>
最后,您可以将图像显示为<?php echo $image['url']; ?>
<?php echo $image['url']; ?>
To get the text or some other contents from ACF 从ACF获取文本或其他一些内容
$variable = get_field('field_name');
Another Important thing is that you have to use render of the variable to print the image that you have obtained Usage of print_r() will lead us to display the image as per our resolutions. 另一个重要的事情是,您必须使用变量的渲染来打印获得的图像,使用print_r()会导致我们按照分辨率显示图像。
For more documentation visit: https://www.advancedcustomfields.com/resources/image/ 有关更多文档,请访问: https : //www.advancedcustomfields.com/resources/image/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.