我看不到一个简单的方法,如果你深入挖掘,可能会有,如果你处理的列表需要这种继承人的导航,使用导航菜单可能更好
如果您对备选方案感兴趣,我在这里找到了一个解决方案:
http://brassblogs.com/code-snippets/add-current-category-ancestor-to-wp_list_categories
这里有一个稍微修改过的版本:
$args = array(
\'sort_column\' =>\'name\',
\'sort_order\' => \'asc\',
\'style\' =>\'list\',
\'depth\' =>\'0\',
\'hierarchical\' =>\'true\',
\'title_li\' =>\'0\',
\'hide_empty\' =>\'1\',
);
echo add_category_ancestor_class($args);
function add_category_ancestor_class($args) {
$list_args = $args;
$list_args[\'echo\'] = \'0\';
$catlist = wp_list_categories($list_args);
if ( is_category() ) {
//Get the active category id
global $cat;
$curr_cat = get_category($cat);
$catid = $curr_cat->cat_ID;
//Find the top level id and number of levels
while ($catid){
$curr_cat = get_category($catid);
$catid = $curr_cat->category_parent;
$id[] = $curr_cat->cat_ID;
}
//How many levels more than two set hierarchical ancestor?
//Count from 1 array from 0 : 1:0=Current 2:1=Parent >2:1 all Ancestors
if( count($id) > 2){
$max=count($id)-1; //Array elements zero based = count - 1
$extra_class=\'current-cat-ancestor\';
for ( $counter = 1; $counter <= $max; $counter ++) {
$cat_ancestor_class = \'cat-item cat-item-\'. $id[$counter];
$amended_class = $cat_ancestor_class . \' \' . $extra_class;
$catlist = str_replace($cat_ancestor_class, $amended_class, $catlist );
}
}
}
$menu = str_replace( array( "\\r", "\\n", "\\t" ), \'\', $catlist );
return $menu;
}