Monday, 26 August 2013

Woocommerce: How do I show subcategories from a specific category as text? Eg: Artists

Woocommerce: How do I show subcategories from a specific category as text? Eg: Artists References I am looking at this code, by NAME Refered from: Show Subcategories from a specific category function woocommerce_subcats_from_parentcat_by_NAME($parent_cat_NAME) { $IDbyNAME = get_term_by(\'name\', $parent_cat_NAME, \'product_cat\'); $product_cat_ID = $IDbyNAME->term_id; $args = array( \'hierarchical\' => 1, \'show_option_none\' => \'\', \'hide_empty\' => 0, \'parent\' => $product_cat_ID, \'taxonomy\' => \'product_cat\' ); $subcats = get_categories($args); echo \'
    \'; foreach ($subcats as $sc) { $link = get_term_link( $sc->slug, $sc->taxonomy ); echo \'
  • \'.$sc->name.\'
  • \'; } echo \'
\'; } but I have no idea how to implement it. Let say I have a category Artists. And subcategories Andy, Jennifer, and Mike. How do I display the name of the artists, which is a subcategory. I used this: $terms_as_links = get_the_term_list( $post->ID, \'product_cat\', \'\', \', \', \'\' ); echo $terms_as_links; But this would display all the categories associated with it. I\'ll get Genre, Year, and Edition. How do I display the subcategory within Artists instead? So that I get: Mike, the artist of this song.

No comments:

Post a Comment