Last active
August 29, 2015 14:10
-
-
Save 1shiharat/1cf4dd4880dba46fb935 to your computer and use it in GitHub Desktop.
カンマ区切りでカテゴリを出力
This file contains 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
<?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