输出当前自定义分类术语的子项与图像

时间:2012-10-03 14:07:41

标签: image taxonomy children

只是想知道是否有人可以帮助解决这个问题 - 几天来敲我的头......

从自定义分类页面(taxonomy_genre.php),我需要输出带有图像的子术语。

我正在使用'Taxonomy Images'插件来设置图像。

以下代码 - 如果有人能给我一些指示,请提前感谢!

代码#1输出所有条款,包括父条款。 代码#2输出正确的术语但没有图像

基本上我正试图合并两者。

代码#1:

     $current_term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );

$args = array(
                            'taxonomy'     => $current_term->taxonomy,
                            'child_of'     => $current_term->term_id,
                                'term_args'    => array(
                                'orderby'      => 'id',
                                'order'        => 'ASC',
                                'hierarchical' => 0,

                                ),

                            );

    $cats = apply_filters( 'taxonomy-images-get-terms', '', $args );

foreach ($cats as $cat) {

echo '<li><a href="' . get_category_link($cat) . '" title="'. $cat->name .'">' ;
echo wp_get_attachment_image( $cat->image_id, 'detail' );
echo $cat->name ;
echo '</a></li>';
}

代码#2

$current_term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$cats = wp_list_categories( array(
    'child_of' => $current_term->term_id,
    'taxonomy' => $current_term->taxonomy,
    'hide_empty' => 0,
    'hierarchical' => false,
    'depth'  => 2,
    'title_li' => ''
    ));
foreach ((array)$cats as $cat) {
$catdesc = $cat->category_description;
echo '<li><a href="'. get_category_link($cat).'" title="'. $cat->cat_name .'">'. wp_get_attachment_image( $cat->image_id, 'detail' ) . $cat->cat_name . '</a></li>'; }

1 个答案:

答案 0 :(得分:0)

已排序 - 已使用:

'parent'=&gt; $ current_term-&GT; term_id,

而不是:

child_of =&gt; $ current_term-&GT; term_id,