Created
November 5, 2013 18:37
-
-
Save wpexplorer/7323824 to your computer and use it in GitHub Desktop.
// Displays the first category of a given portfolio post, but show all cateegories on the single post
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
function wpex_portfolio_first_cat($postid=false) { | |
global $post; | |
$postid = $postid ? $postid : $post->ID; | |
$cats = get_the_terms( $postid, 'portfolio_category' ); | |
$output = ''; | |
if( $cats ) { | |
$cats_count = count($cats); | |
if ( is_singular('portfolio') ) { | |
$count=0; | |
foreach( $cats as $cat ) { | |
$count++; | |
if ( $cats_count == $count ) { | |
$output .= '<a href="'. get_term_link($cat->slug, 'portfolio_category') .'" title="'. $cat->name .'">'. $cat->name .'</a>'; | |
} else { | |
$output .= '<a href="'. get_term_link($cat->slug, 'portfolio_category') .'" title="'. $cat->name .'">'. $cat->name .'</a>, '; | |
} | |
} | |
} else { | |
$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