How to display custom taxonomy hierarchically in template?
I’ve successfully been able to include my custom taxonomy in a template page for a hierarchical taxonomy. However I cannot figure out what I need to do in the code for the template page to display the items according to their hierarchy.
<?php echo get_the_term_list( get_the_ID(), 'clipart-theme', "Theme: ", ' » ' ) ?>
It just displays the parent & child terms alphabetically. What I want is for it to reflect the relationship.
For example, if my hierarchy is Beer (parent category) and then Amstel Light (child category), the above code outputs as Amstel Light >> Beer, but I want it to display as Beer >> Amstel Light.
What do I need to do to make this happen?
Oh and maybe I should mention that I am displaying these items on a custom post type.
Hi, the forums now really sucks. I don’t have any reply in my last 5-6 threads.
What you are want to do is breadcrumb trail. you can use this pluin http://wordpress.org/extend/plugins/breadcrumb-trail/ and see if it works. Not sure if it will work with custom taxonomy but the current version says compatible upto WP 3.0.4 so no harm to try 🙂
I’ll give it a try, thanks for the tip! Glad it works in a template, that’s key.
If you are stilling looking I think what you want is the wp_list_categories function – specify the custom taxonomy name in the taxonomy argument. It is working for me with a template specific to a custom post type.
For example add the following to your template:
<ul> <?php $args = array( 'orderby' => 'ID', 'order' => 'ASC', 'style' => 'list', 'show_count' => 1, 'hide_empty' => 0, 'use_desc_for_title' => 1, 'child_of' => 0, 'hierarchical' => true, 'title_li' => __( 'Directory Organization' ), 'show_option_none' => __('No Directory Orgs'), 'number' => NULL, 'echo' => 1, 'depth' => 0, 'current_category' => 0, 'pad_counts' => 1, 'taxonomy' => 'directory', 'walker' => 'Walker_Category' ); wp_list_categories($args); ?> </ul>
- The topic ‘How to display custom taxonomy hierarchically in template?’ is closed to new replies.