本文介绍了在自定义分类模板中获取自定义字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我设法列出了自定义父分类法的所有直接子代.
I've managed to list out all direct children of the custom parent taxonomy..
Chocolates Marshmallows Popcorn ..and so on...下面是这段代码.
<?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); if ($term->parent == 0) { $terms = get_terms( 'product-type', 'parent='.$term->term_id ); } else { $terms = get_terms( 'product-type', 'parent='.$term->parent ); } foreach($terms as $term) { echo ' <div class="snack_type"> <a href="' . get_term_link( $term ) . '">' . $term->name . '</a> </div> '; } ?>上面显示的每个分类法都有一个带有自定义字段(高级自定义字段)的图像.如何在每个生成的div中显示自定义字段(product_type_image)?像这样
Each of the taxonomies showing above has an image uploaded to it with custom fields (advanced custom fields). How do i show a custom field (product_type_image) in each of the div that gets generated? like this
Chocolates [product_type_image] Marshmallows [product_type_image] Popcorn [product_type_image] ..and so on...我正在尝试
$productimage = get_field('product_type_image', $term->taxonomy.'_'.$term->term_id);但尝试显示任何内容均未成功
but it was unsuccessful to try to show anything
推荐答案添加此行
echo '<img src="' . get_field('product_type_image', $term->taxonomy . '_' . $term->term_id) . '"/>';所以它应该看起来像这样
so it should look like this
<?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); if ($term->parent == 0) { $terms = get_terms( 'product-type', 'parent='.$term->term_id ); } else { $terms = get_terms( 'product-type', 'parent='.$term->parent ); } foreach($terms as $term) { echo '<div class="snack_type"><a href="' . get_term_link( $term ) . '">' . $term->name . '</a></div>'; echo '<img src="' . get_field('product_type_img', $term->taxonomy . '_' . $term->term_id) . '"/>'; } ?>更多推荐
在自定义分类模板中获取自定义字段
发布评论