thanx very much, your code working fine, but one problem for me.
This code returns an unordered list of all child terms, but my structure has many levels, and I want now to display only one child level of current page, something like ‘depth=1’ in wp_list_categories.
How may i modify this code? Woul be very pleasant for u!
Try it with this:
$term_slug = get_query_var( 'term' );
$taxonomyName = get_query_var( 'taxonomy' );
$current_term = get_term_by( 'slug', $term_slug, $taxonomyName );
$termchildren = get_term_children( $current_term->term_id, $taxonomyName);
if($termchildren && ( !is_wp_error( $termchildren ))){
echo '<ul>';
foreach ($termchildren as $child) {
$term = get_term_by( 'id', $child, $taxonomyName );
if($current_term->term_id == $term->parent){
echo '<li><a href="' . get_term_link( $term->name, $taxonomyName ) . '">' . $term->name . '</a></li>';
}
}
echo '</ul>';
}
Or this 🙂
$term_slug = get_query_var( 'term' );
$taxonomyName = get_query_var( 'taxonomy' );
$current_term = get_term_by( 'slug', $term_slug, $taxonomyName );
$args_list = array(
'taxonomy' => 'item', // or use $taxonomyName for all taxonomies
'show_count' => true,
'hierarchical' => true,
'child_of' => $current_term->term_id,
'hide_empty' => '0',
'title_li' => '',
'echo' => '0',
);
echo wp_list_categories($args_list);
to avoid the message No categories if there is no child categories, you can use after 3rd string ($current_term…) keesiemeijer’s condition code 🙂
$termchildren = get_term_children( $current_term->term_id, $taxonomyName);
if($termchildren && ( !is_wp_error( $termchildren ))) {
// whole section with $args_list and wp_list_categories($args_list) here;
}