Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
I wrote this for myself a long time ago, I use it to this day:
<ul class="main-cat-menu">
<?php
//Вывод рубрик товаров Woocommerce
$args = array(
'number' => $number,
'orderby' => 'term_id',
'order' => 'ASC',
'hide_empty' => $hide_empty,
'include' => $ids,
'parent' => '0'
);
$product_categories = get_terms('product_cat', $args);
$count = count($product_categories);
if ($count > 0) {
foreach ($product_categories as $product_category) {
$args = array(
'hierarchical' => 1,
'show_option_none' => '',
'hide_empty' => 0,
'parent' => $product_category->term_id,
'taxonomy' => 'product_cat'
);
$numberOflinks = $numberOflinks + 1;
$subcats = get_categories($args);
if (empty($subcats)) {
$arrow = 'no-arrow';
} else {
$arrow = '';
}
echo '<li class="' . $product_category->slug . ' ' . $arrow . '">
<a href="' . get_term_link($product_category) . '">
<img src="' . get_template_directory_uri() . '/img/svg/' . $numberOflinks . '.svg" height="25" class="svg" />
' . $product_category->name . '
</a>
';
if (!empty($subcats)) {
echo '<ul>';
}
foreach ($subcats as $sc) {
$link = get_term_link($sc->slug, $sc->taxonomy);
echo '<li><a href="' . $link . '">' . $sc->name . '</a></li>';
}
if (!empty($subcats)) {
echo '</ul>';
}
echo '
</li>';
}
}
?>
</ul>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question