使用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/
答案 0 :(得分:0)
<?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/