此代码来自codex.
/* == If In Parent Category... ==============================*/
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;
}
}
我在主题中使用它,如下所示:if ( post_is_in_descendant_category( 11 ) ) ...
11
), 然而,我希望它能接受子弹。有没有办法以某种方式修改此代码以接受slug?