【发布时间】:2021-01-30 16:22:26
【问题描述】:
如果该类别有子类别,我需要在<li> 元素中添加像dropdown 这样的额外类:
<ul class="departments__links">
<?php
$taxonomy = 'product_cat';
$orderby = 'name';
$show_count = 0; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$title = '';
$empty = 0;
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty
);
$all_categories = get_categories( $args );
foreach ($all_categories as $cat) {
if ($cat->category_parent == 0) {
$category_id = $cat->term_id;
echo '<li class="departments__item EXTRA-CLASS-HERE"><a href="'. get_term_link( $cat->slug, 'product_cat' ) .'" class="departments__item-link">'. $cat->name . '</a></li>';
}
}
?>
</ul>
【问题讨论】:
标签: php wordpress woocommerce