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?


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'); ?> 
  • Thank you!, I used <?php wp_list_categories($args);?> and defind an $args array :) – galengodis Mar 13 '12 at 18:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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