functions.phpに以下のコードを記述
if ( ! function_exists( 'post_is_in_descendant_category' ) ) {
function post_is_in_descendant_category( $cats, $_post = null ) {
foreach ( (array) $cats as $cat ) {
$descendants = get_term_children( (int) $cat, 'category' );
if ( $descendants && in_category( $descendants, $_post ) )
return true;
}
return false;
}
}
if文の書き方
<?php if ( in_category('親カテゴリID') || post_is_in_descendant_category('親カテゴリID') ): ?>
// 「親カテゴリ」に属していたら出力される内容
<?php else: ?>
// それ以外の出力内容
<?php endif; ?>
You should take part in a contest for one of the highest quality blogs on the web. I will recommend this web site! Bab Creight Gorrian