39 lines
1.3 KiB
PHP
39 lines
1.3 KiB
PHP
<?php
|
|
|
|
$arg_cat = array(
|
|
'exclude' => get_expression_parts(),
|
|
'order' => 'ASC',
|
|
'taxonomy' => 'category',
|
|
'hide_empty' => false
|
|
);
|
|
$categories = get_categories($arg_cat);
|
|
$current_term = get_queried_object();
|
|
|
|
// Получаем ID текущей категории или категорий поста
|
|
$current_term_ids = [];
|
|
if (is_single()) {
|
|
$current_term_ids = wp_get_post_categories($current_term->ID);
|
|
} elseif (is_category()) {
|
|
$current_term_ids[] = $current_term->term_id;
|
|
}
|
|
|
|
$firstElement = array_shift($categories);
|
|
array_push($categories, $firstElement);
|
|
|
|
foreach ($categories ?? [] as $cat) {
|
|
if ($cat->slug === 'uncategorized') continue;
|
|
$icon = get_field('icon', 'category_' . $cat->term_id);
|
|
$bg_image = get_field('bg_image', 'category_' . $cat->term_id);
|
|
|
|
if($bg_image){
|
|
|
|
$class = in_array($cat->term_id, $current_term_ids) ? 'is-active' : '';
|
|
|
|
echo "<a href='" . get_category_link($cat->term_id) . "' class='menu-vertical__item " . $class . "'>
|
|
<span class='menu-vertical__item-icon'><img src='" . $icon . "' alt=''></span>
|
|
<span class='menu-vertical__item-text'>$cat->name</a></span>
|
|
</a>
|
|
";
|
|
}
|
|
}
|