/ Published in: PHP

This snippet will help you to use the mother category, the ones with parent => 0, as your classes ready to be stylezed in your CSS!
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$categorie = get_the_terms($post->ID, 'ad_cat'); foreach( $categorie as $categoria ){ if( $categoria->parent != 0 ){ $cat = $categoria; while( $cat->parent != 0){ $cat = get_term( $cat->parent, 'ad_cat'); } echo '<a href="'.get_term_link($categoria->slug, 'ad_cat').'" class="'.$cat->slug.'" rel="tag">'.$categoria->name.'</a> '; } else { echo '<a href="'.get_term_link($categoria->slug, 'ad_cat').'" class="'.$cat->slug.'" rel="tag">'.$categoria->name.'</a> '; } }
Comments
