Skip to content

Instantly share code, notes, and snippets.

@wpexplorer
Created November 5, 2013 18:33
Show Gist options
  • Save wpexplorer/7323764 to your computer and use it in GitHub Desktop.
Save wpexplorer/7323764 to your computer and use it in GitHub Desktop.
// Displays the first category of a given portfolio
if ( ! function_exists( 'wpex_portfolio_first_cat' ) ) {
function wpex_portfolio_first_cat($postid=false) {
global $post;
$postid = $postid ? $postid : $post->ID;
$cats = get_the_terms( $postid, 'portfolio_category' );
$output = '';
if( $cats ) {
$count=0;
foreach( $cats as $cat ) {
$count++;
if ( $count == 1 ) {
$output .= '<a href="'. get_term_link($cat->slug, 'portfolio_category') .'" title="'. $cat->name .'">'. $cat->name .'</a>';
}
}
}
return $output;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment