php - 如何在 Wordpress 中使用简码显示子字段(图像)?
问题描述
这些是自定义字段组成:
1 组页脚
1.1 组 Col2
1.1.1 bbcimg(这是图片ID)
1.1.2 bbc-rss(这是 RSS 提要 ID)
我有以下代码显示 bbc-rss:
<div class="col-md-3">
<?php
$footer = get_field('footer'); // 'footer' is your parent group
$col2 = $footer['col2']; // 'col2' is your child group
?>
<div class="widget_item widget_latest sm-m-top-50">
<h4 id="white" class="text-white">Latest News</h4>
<div class="widget_latst_item m-top-30">
<div class="item_icon"><img src="<?php bloginfo('template_directory');?>/img/rss/bbc_rss.png" alt="" /></div>
<div id="gris" class="widget_latst_item_text">
<p><?php echo $col2['bbc-rss'];?></p>
</div>
</div>
<div class="widget_latst_item m-top-30">
<div class="item_icon"><img src="<?php bloginfo('template_directory');?>/img/rss/reuters_rss.png" alt="" /></div>
<div id="gris" class="widget_latst_item_text">
<p><?php echo $col2['reuters-rss'];?></p>
</div>
</div>
<div class="widget_latst_item m-top-30">
<div class="item_icon"><img src="<?php bloginfo('template_directory');?>/img/rss/cnbc.jpg" alt="" /></div>
<div id="gris" class="widget_latst_item_text">
<p><?php echo $col2['cnbc-rss'];?></p>
</div>
</div>
</div><!-- End off widget item -->
</div><!-- End off col-md-3 -->
我创建了具有以下属性的图像字段 bbcimg:
- 字段标签:bbcimg
- 字段名称:bbcimg
- 字段类型:图片
- 指示: -
- 要求:否
- 返回格式:图像数组
- 预览尺寸:中(300x300)
- 图书馆:全部
- 最小值:宽度 40 像素,高度 40 像素 文件大小 - MB
- 最小值:宽度 - px,高度 px - 文件大小 - MB
- 允许的文件类型:-
- 条件逻辑:-
- 包装器属性: -
问题:
如何编写在网站上显示图片的逻辑?
非常感谢您!
一直在尝试使用
解决方案
首先,您需要找出自定义字段中返回的内容。print_r
在某处添加一个好的旧代码:
<?php print_r($col2['bbcimg']) ?>
这将打印出一个值数组,例如 Array('url' => 'http....something.jpg', 'size'=>'full', ..etc)
然后,您可以确定哪个数组值为您提供了图像的完整 URL。假设在这种情况下它将是一个名为 的字段url
,那么您可以按如下方式使用该值:
<div id="gris" class="widget_latst_item_text">
<img src="<?php echo $col2['bbcimg']['url']; ?>" alt=""/>
<p><?php echo $col2['bbc-rss'];?></p>
</div>
推荐阅读
- go - 为什么标准库 bufio.Read(p []byte) (int, err) 在 Go 中检查 len(p) 而不是 cap(p)
- php - 如何修复无法在 postgresql 中执行查询错误?
- rust - impl 中的生命周期与 trait 中的方法不匹配
- javascript - 为什么表单值从控制台日志中消失?
- vue.js - 如何让 v-pagination 从用户选择的特定页面开始(而不是从第 1 页开始)?
- docker - 来自外部配置的多个绑定挂载
- qt - 如何在 QWebView 中显示动态创建的图像?
- gensim - 评估 doc2vec 的准确性
- c++ - 如何让类相互继承?
- discord.py - discord.py 如何使 JSON 文件在 Heroku 上工作