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 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.

 $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
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


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.