我想在侧边栏中显示一个带有自定义分类列表的小部件。一切正常,但是当我添加一个子类别时,这会显示为一个类别而不是正确的顺序(在您的父级下)
例如,在我的后端:
CARS -Ferrari -LAMBORGHINI BIKE MOTO
在前端:
FERRARI CARS BIKE MOTO LAMBORGHINI
$terms = get_terms( array(
'taxonomy' => 'categorie_area_riservata',
'hide_empty' => false,
) );
echo '<ul class="widget_categories">';
// loop through all terms
foreach( $terms as $term ) {
// Get the term link
$term_link = get_term_link( $term );
if( $term->count > 0 )
// display link to term archive
echo '<li class="cat-item"><a href="' . esc_url(
$term_link ) . '">' . $term->name .'</a></li>';
elseif( $term->count !== 0 )
// display name
echo '' . $term->name .'';
}
echo '</ul>';
我以简单的方式解决。
echo '<ul class="categories">';
wp_list_categories(
array(
'taxonomy' => 'categorie_area_riservata',
'title_li' => '',
'depth' => 2,
)
);
echo '</ul>';
和css类
ul.categories a {color:#444444;}
ul.categories a:hover {color:#1c57a1;}
/*child term*/
ul.children {padding-left:50px !important;}
ul.children li {
padding-bottom: 0 !important;
padding-top: 0px;
margin-top: 3px !important;
}