• Resolved camelgraph

    (@camelgraph)


    Let’s say i have custom taxonomy named “Location” with hierarchial structure like in the following image :

    https://i44.tinypic.com/20zbf5y.jpg

    On the taxonomy archive template (taxonomy.php) , i want to display links to all DIRECT CHILD of the current taxonomy being viewed.

    So for example, if someone view the “ASIA” archive page they will see link to CHINA, INDIA, and JAPAN archive page only and exclude the “grandchildren” taxonomy.

    Then if someone view the JAPAN archive page they will see a link to FUKUOKA, HOKKAIDO, OKINAWA, and TOKYO only . Same behavior until it reach the taxonomy with no children and obviously nothing will be displayed

    Please help me what to do, i’ve tried several method but none of them work.

    Most of the solution i found only manage to display ALL the children taxonomy including the grandchildren.

    So instead work like i explained above, the “ASIA” archive page will display all link to CHINA, INDIA, JAPAN, Fukooka, Hokkaido, Tokyo, Akishima, …..

    I want to display ONLY the direct children of the current taxonomy and exclude the grandchildren.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter camelgraph

    (@camelgraph)

    SOLVED, doing some experiment with wp_list_categories and get_term_by. I’ve added this code to my taxonomy.php

    <?php
    
    //first get the current term
    $current_term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
    
    //then set the args for wp_list_categories
     $args = array(
        'child_of' => $current_term->term_id,
        'taxonomy' => $current_term->taxonomy,
    	'hide_empty' => 0,
    	'hierarchical' => true,
    	'depth'  => 1,
    	'title_li' => ''
        );
     wp_list_categories( $args );
    ?>

    Thanks camelgraph for sharing this!

    Thank you camelgraph, that really helped.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display direct children of the current custom taxonomy in taxonomy.php template’ is closed to new replies.