我成功地使用了helgatheviking在这篇文章中的回答:Show children of top level category only 请参见下面的代码:
// get the category object for the current category
$thisCat = get_category( get_query_var( \'cat\' ) );
// if not top-level, track it up the chain to find its ancestor
while ( intval($thisCat->parent) > 0 ) {
$thisCat = get_category ( $thisCat->parent );
}
//by now $thisCat will be the top-level category, proceed as before
$args=array(
\'child_of\' => $thisCat->term_id,
\'hide_empty\' => 0,
\'orderby\' => \'name\',
\'order\' => \'ASC\'
);
$categories=get_categories( $args );
foreach( $categories as $category ) {
echo \'<a href="\' . get_category_link( $category->term_id ) . \'" title="\' . sprintf( __( "View all posts in %s" ), $category->name ) . \'" \' . \'>\' . $category->name.\'</a>\'; }
?>
然而,在这个子类别列表中,我需要突出显示当前类别。我相信有一个简单的答案,但我自己也弄不明白。