如果a
是类别slug,则以下代码可以工作-
add_action(\'template_include\', \'wpse129481_template_include\');
function wpse129481_template_include($t)
{
// is category archive page
if( is_category() )
{
// current queried category id from queried object
$child_id = get_queried_object_id();
// parent category object, getting it by slug.
$parent_cat = get_term_by(\'slug\', \'a\', \'category\');
// current category object, can also be used get_queried_object()
$child_cat = get_term($child_id, \'category\');
// important part here is the cat_is_ancestor_of() function.
// it checks if first category is parent/grand parent of second
if( isset($parent_cat->term_id)
&& isset($child_cat->term_id)
&& $parent_cat->term_id != $child_cat->term_id
&& cat_is_ancestor_of( $parent_cat, $child_cat )
)
{
locate_template( array(\'category-cat-a.php\') );
}
}
return $t;
}