1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | //WordPressのカテゴリのテンプレートで、属する親カテゴリに合わせて、 //子カテゴリの内容を切り替える関数 function in_category_family( $parent ) { if ( empty ( $parent ) ) return false; if ( in_category( $parent ) ) return true; $parent = get_category( $parent ); foreach ( (get_the_category()) as $child ) { $child = get_category( $child ->cat_ID); if ( cat_is_ancestor_of( $parent , $child ) ) return true; } return false; } //if ( function_exists('in_category_family') && in_category_family('親カテゴリのスラッグ') ){ //実行内容 //} |