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 am currently working on a WooCommerce site.I managed to set it up,do some configuration according to my plan.Now i want to display product categories alongside each products in product catalog,and also want to display how many time the product has been sold too.

I have done some searching and found this code,which displays product categories,but i want to display category with link to it.

 <?php
 $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
 $parents = get_the_terms($term->parent, get_query_var('taxonomy') );

 echo "<div class='product-cat'>";
 echo "In"." "." ";
 foreach( $parents as $parent ) {
 echo $parent->name;
 }
?> 

Please help out on this.Thanks in advance.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Try looking in the Codex for answers. You will find that get_term_link() creates links to terms.

foreach( $parents as $parent ) {
    echo get_term_link( $parent );
}
share|improve this answer
    
Thanks for the answer. –  user946131 Apr 3 '13 at 18:58
    
Thanks to @toscho for the edit. –  helgatheviking Apr 3 '13 at 21:07

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.