Return to Snippet

Revision: 46188
at May 14, 2011 00:02 by Pr0v4


Initial Code
$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> ';
	}
}

Initial URL

                                

Initial Description
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!

Initial Title
Use category slug as CSS class

Initial Tags
wordpress, category

Initial Language
PHP