Initial commit
This commit is contained in:
34
partials/category-menu-for-category.php
Normal file
34
partials/category-menu-for-category.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
$arg_cat = array(
|
||||
'exclude' => '17, 20, 21',
|
||||
'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);
|
||||
|
||||
$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>
|
||||
";
|
||||
}
|
||||
Reference in New Issue
Block a user