certainlyakey
3/3/2014 - 12:16 PM

Wordpress - the_category expanded to support custom taxonomies, with possibility to exclude certain categories or terms

Wordpress - the_category expanded to support custom taxonomies, with possibility to exclude certain categories or terms

//the_category expanded to support custom taxonomies, with possibility to exclude certain categories/terms
function catOut($category,$tax,$showlink) {
	$text = '';
	$text .= '<li>';
	if ($showlink) {$text .= '<a href="' . get_term_link($category->term_id,$tax).'" title="'.$category->name.'"'.'>';}
	$text .= $category->name;
	if ($showlink) {$text .= '</a>';}
	$text .= '</li>';
	return $text;
}
function the_category_except($tax,$excludedcats = array(),$showlink = true, $prefix = '<ul>', $suffix = '</ul>'){
  global $post;
	$categories = get_the_terms($post->ID,$tax);
	if (!empty($categories)) {
		echo $prefix;
		foreach($categories as $category) {
			if ($excludedcats) {
				if ( !in_array($category->term_id, $excludedcats)) {
					echo catOut($category,$tax,$showlink);
				}
			} else {
				echo catOut($category,$tax,$showlink);
			}
		}
		echo $suffix;
	}
}