最近改版个wordpress网站,然后需要列出来自定义分类法的分类。但是wp_list_categories函数默认的样式不方便用框架,如果正常改的话,搞个Walke函数也不是很灵活,查了下资料,这样就很方便。
<ul class="our__list">
<?php
$categories = get_categories( [
'taxonomy' => 'category',
'type' => 'post',
'child_of' => 0,
'parent' => '',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 1,
'hierarchical' => 1,
'exclude' => '',
'include' => '',
'number' => 0,
'pad_counts' => false,
] );
if( $categories ) {
foreach( $categories as $cat ) {
?>
<li class="our__list-class">
<a
href="<?php echo get_category_link($cat->term_id); ?>"
>
<?php echo $cat->name; ?>
</a>
</li>
<?php
}
}
?>
</ul>
代码来源:https://stackoverflow.com/questions/38944722/add-classes-to-wp-list-categories。
留下您的宝贵意见