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.

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?

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
2  
Also look at wp_list_categories –  soulseekah Mar 13 '12 at 15:06
add comment

1 Answer

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>
    <ul>
    <?php wp_list_categories('taxonomy' => 'kategori'); ?> 
    </ul>
</div>
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
add comment

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.