Created
October 25, 2013 04:43
-
-
Save wpexplorer/7149524 to your computer and use it in GitHub Desktop.
Portfolio first cat link
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
// 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