Created
November 5, 2013 18:33
-
-
Save wpexplorer/7323764 to your computer and use it in GitHub Desktop.
// Displays the first category of a given portfolio
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
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