【发布时间】:2015-11-02 08:53:18
【问题描述】:
使用 ACF,我已将自定义图像字段添加到一组特定的自定义帖子标签中。我遇到的问题是我无法显示图像。是的,我已经在标签中添加了一张图片并进行了更新。
$term_id = 26;
$taxonomy_name = 'tags';
$termchildren = get_term_children( $term_id, $taxonomy_name );
foreach ( $termchildren as $child ) {
$term = get_term_by( 'id', $child, $taxonomy_name );
$tag_image = get_field('tag_image');
echo '<a href="?categories=' . $term->slug . '">'. $term->name . '</a>';
echo $tag_image; //this bit doesn't work :(
}
已修复,新代码为:
<?php
$term_id = 26;
$taxonomy_name = 'tags';
$termchildren = get_term_children( $term_id, $taxonomy_name );
foreach ( $termchildren as $child ) {
$term = get_term_by( 'id', $child, $taxonomy_name );
$tag_image = get_field('tag_image', $term);
echo '<a href="?categories=' . $term->slug . '" class="one-third column">'. $term->name;
?>
<? if( !empty($tag_image) ): ?>
<img src="<? echo the_field('tag_image', $term); ?>" />
<?php endif;
echo '</a>';
}
?>
修复资源在这里http://www.advancedcustomfields.com/resources/get-values-from-a-taxonomy-term/
【问题讨论】:
-
负载会发生什么?它抛出404,不发出请求等?生成的来源是什么?
-
它显示标签列表但没有图像,没有错误消息
-
源中有
<img...吗? -
不,只是包裹在
a标签中的标签列表 -
在 ACF 中为图像字段设置返回值有三个选项,它们都不起作用,例如图片数组、图片网址、图片ID
标签: php advanced-custom-fields custom-taxonomy