WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have made a product page. Wich lists all products site.com/products. At the product page there is a navigation wich lists all the terms in the taxonomy 'kategori'. The taxonomy is set to hierarchical, so i can make parent terms. I list all the terms with:

  <div class="produkt_nav"><h3><a href="/produkter/">Produkter</a></h3>
  <?php $cam_brands = get_terms('kategori', 'hide_empty=1'); ?>
    <?php foreach( $cam_brands as $brand ) : ?>
        <a href="<?php echo get_term_link( $brand->slug, 'kategori' ); ?>">
          <?php echo $brand->name; ?>

    <?php endforeach ?>


It gives me:

  • Main category
  • Main 2 category
  • Parent to main 3
  • Main 3 category
  • Main 4 category

I need to change the code so i get it to show:

- Main category
- Main 2 category
- Main 3 category   
  X Parent to main 3
- Main 4 category

How can put a different class to parent terms and list the terms as a tree?

share|improve this question
Check for $brand->parent_ID, if set apply new class. Other than that, I'd suggest you use a custom Walker codex.wordpress.org/Function_Reference/Walker_Class instead of a loop. – soulseekah Mar 13 '12 at 15:03
Also look at wp_list_categories – soulseekah Mar 13 '12 at 15:06
up vote 1 down vote accepted

You can use wp_list_categories() where the hierarchical argument is set to true by default , something like this:

<div class="produkt_nav"><h3><a href="/produkter/">Produkter</a></h3>
    <?php wp_list_categories('taxonomy' => 'kategori'); ?> 
share|improve this answer
Thank you!, I used <?php wp_list_categories($args);?> and defind an $args array :) – galengodis Mar 13 '12 at 18:44

Your Answer


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.