WordPress.org

Ready to get started?Download WordPress

Forums

Taxonomy Images
display children of current term only (3 posts)

  1. elbego
    Member
    Posted 1 year ago #

    Hi!

    Jsut wondering if anyone can help with this - banging my head for days...

    Wanting to output the children terms with images of the current term in CPT taxonomy in taxonomy_genre.php.

    The following code outputs all terms including parent terms.

    my code:

    $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="'. strip_tags($catdesc) .'">'. $cat->cat_name . '</a><a href="' . get_category_link($cat) . '" title="'. $cat->name .'">' ;
    echo wp_get_attachment_image( $cat->image_id, 'detail' );
    echo $cat->name ;
    echo '</a></li>';
    }

    http://wordpress.org/extend/plugins/taxonomy-images/

  2. elbego
    Member
    Posted 1 year ago #

    Sorry - have removed the duplicated code.

    $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>';
    }
  3. elbego
    Member
    Posted 1 year ago #

    Equally, this produces the correct result albeit without any images!

    $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>'; }

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic