Skip to content

Instantly share code, notes, and snippets.

@certainlyakey
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save certainlyakey/9323820 to your computer and use it in GitHub Desktop.
Save certainlyakey/9323820 to your computer and use it in GitHub Desktop.
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment