Files
agroexpert/partials/rubrics-mobile-menu.php

60 lines
2.2 KiB
PHP
Raw Normal View History

2025-05-10 00:00:09 +03:00
<?php
// Получаем текущие рубрики из меню
$categories = get_categories_from_menu_exact_order('rubrics');
// Текущая категория или пост
$current_term = get_queried_object();
$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;
}
?>
<div class="menu-vertical mobile">
<div class="menu-vertical__head">
<?php if (is_category()) : ?>
<span><?= esc_html($current_term->name); ?></span>
<?php elseif (is_single()) : ?>
<span><?= esc_html(get_cat_name($current_term_ids[0] ?? 0)); ?></span>
<?php else : ?>
<span>Рубрики</span>
<?php endif; ?>
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_373_15802)">
<path d="M7 10L12 15L17 10" stroke="#7C7C7C" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" />
</g>
<defs>
<clipPath id="clip0_373_15802">
<rect width="24" height="24" fill="white" />
</clipPath>
</defs>
</svg>
</div>
<div class="menu-vertical__inner">
<?php foreach ($categories as $cat) : ?>
<?php
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' : '';
?>
<a href="<?= esc_url(get_category_link($cat->term_id)); ?>" class="menu-vertical__item <?= esc_attr($class); ?>">
<span class="menu-vertical__item-icon">
<?php if ($icon): ?>
<img src="<?= esc_url($icon); ?>" alt="" />
<?php endif; ?>
</span>
<span class="menu-vertical__item-text"><?= esc_html($cat->name); ?></span>
</a>
<?php endforeach; ?>
</div>
</div>