在中运行条件检查foreach
循环使用is_category($term-name)
将类变量指定给active
如果它与$term->name
$terms = get_terms( \'category\' );
echo \'<ul>\';
foreach ( $terms as $term ) {
$class = ( is_category( $term->name ) ) ? \'active\' : \'\'; // assign this class if we\'re on the same category page as $term->name
echo \'<li><a href="\' . get_term_link( $term ) . \'" class="\' . $class . \'">\' . $term->name . \'</a></li>\';
}
echo \'</ul>\';