Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

  • ASIA

    • CHINA
    • INDIA
    • JAPAN

      • Fukuoka
      • Hokkaido
      • Okinawa
      • Tokyo

        • Akishima
        • Machida
        • Tachikawa
        • ...
  • AFRICA

  • AMERICA

  • EUROPE

  • ...

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.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

See the Codex. The wp_list_categories allows you to set a child_of and a depth (in this case 1, we only want to go one level down).

See the link to the Codex about styling it; there's a whole host of options.

<?php $term = get_queried_object();
     wp_list_categories(array(
       'taxonomy'=>$term->taxonomy,
       'child_of'=>(int) $term->term_id,
       'hide_empty'=>0,
       'depth'=>1,
  )); ?>

I've only tested this on built-in categories, but this should work for custom taxonomies too.

share|improve this answer
    
Awesome!, this work flawlessly. thank you very much.. –  Faizal Al-Amri Jan 27 '12 at 0:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.