问题是你需要通过$post->ID
为了不return false.
更好地使用is_object_in_taxonomy($object_type, $taxonomy)
并在函数中填写术语和税。它返回(boolean)
, 因此,只需根据结果添加您的类:
echo $class = is_object_in_taxonomy( \'news\', \'your_taxonomy\' ) ? \'current-whatever\' : \'\';
// or: (simplified for readabilities sake:
// set empty and override only in case.
// So you avoid dropping errors if the condition was not met and $current not set.
$class = \'\';
if ( is_object_in_taxonomy( \'news\', \'your_taxonomy\' ) )
echo $class = \'current-whatever\';