Skip to content

Instantly share code, notes, and snippets.

@1shiharat
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1shiharat/1cf4dd4880dba46fb935 to your computer and use it in GitHub Desktop.
Save 1shiharat/1cf4dd4880dba46fb935 to your computer and use it in GitHub Desktop.
カンマ区切りでカテゴリを出力
<?php
$terms = get_the_terms( get_the_ID(), 'category' );
if ( !empty($terms) ) {
if ( !is_wp_error( $terms ) ) {
foreach( $terms as $term_key => $term ) {
// カテゴリー名がhogehogeの場合ループをすっ飛ばす
if( $term->name == 'hogehoge' ) {
continue;
}
if ($term === end($terms)) {
echo $term->name;
} else {
echo $term->name . ' , ';
}
}
}
}
// もしくは
$terms = get_the_term_list( $post->ID, 'category', '', ',', '' );
echo strip_tags( $terms );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment