0

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'); ?>
  <ul>
    <?php foreach( $cam_brands as $brand ) : ?>
      <li>
        <a href="<?php echo get_term_link( $brand->slug, 'kategori' ); ?>">
          <?php echo $brand->name; ?>
        </a>

    <?php endforeach ?>
  </ul>

  </div>

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?

2

1 Answer 1

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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