※なんかうまくいかなかった
ファンクションへ
タクソノミーだけなら下の部分だけでOK
/* For categories */
if ( ! function_exists( 'post_is_in_descendant_category' ) ) :
function post_is_in_descendant_category( $cats, $_post = null ) {
foreach ( (array) $cats as $cat ) {
// get_term_children() accepts integer ID only
$descendants = get_term_children( (int) $cat, 'category' );
if ( $descendants && in_category( $descendants, $_post ) )
return true;
}
return false;
}
function post_is_in_category_slug($slug){
global $post;
$post_id = ( isset($post->ID) ) ? $post->ID : '';
if ( in_category( $slug, $post_id ) || post_is_in_descendant_category( get_term_by('slug',$slug,'category'), $post_id ) ){
return true;
} else {
return false;
}
}
endif; //function_exists 'post_is_in_descendant_category'
/* For taxonomies */
if ( ! function_exists( 'post_is_in_descendant_taxonomy' ) ) :
function post_is_in_descendant_taxonomy( $terms, $taxonomy, $_post = null ) {
foreach ( (array) $terms as $term ) {
// get_term_children() accepts integer ID only
$descendants = get_term_children( (int) $term, $taxonomy );
if ( $descendants && has_term( $descendants, $taxonomy, $_post ) )
return true;
}
return false;
}
function post_is_in_taxonomy_slug($slug, $taxonomy){
global $post;
$post_id = ( isset($post->ID) ) ? $post->ID : '';
if ( has_term( $slug, $taxonomy, $post_id ) || post_is_in_descendant_taxonomy( get_term_by('slug',$slug,$taxonomy), $taxonomy, $post_id ) ){
return true;
} else {
return false;
}
}
endif; //function_exists 'post_is_in_descendant_taxonomy'
//宅
if ( post_is_in_taxonomy_slug('Cat-A', カスタムタクソノミー名) )
//具体例
<?php
if (post_is_in_taxonomy_slug('ホームページ制作', cate_jirei) ):
?>
<?php endif; ?>
//カテ
if ( post_is_in_category_slug('Cat-A')