Last active
August 29, 2015 13:56
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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