add new logic rubrics
This commit is contained in:
@@ -1,12 +1,7 @@
|
||||
<?php
|
||||
|
||||
$arg_cat = array(
|
||||
'exclude' => get_expression_parts(),
|
||||
'order' => 'ASC',
|
||||
'taxonomy' => 'category',
|
||||
'hide_empty' => false
|
||||
);
|
||||
$categories = get_categories($arg_cat);
|
||||
// Получаем текущие рубрики из меню
|
||||
$categories = get_categories_from_menu_exact_order('rubrics');
|
||||
$current_term = get_queried_object();
|
||||
|
||||
// Получаем ID текущей категории или категорий поста
|
||||
@@ -17,9 +12,6 @@ if (is_single()) {
|
||||
$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);
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
<?php
|
||||
$categories = get_categories(array(
|
||||
'exclude' => get_expression_parts(),
|
||||
'orderby' => 'name',
|
||||
'order' => 'ASC',
|
||||
'hide_empty' => false
|
||||
));
|
||||
|
||||
|
||||
$firstElement = array_shift($categories);
|
||||
array_push($categories, $firstElement);
|
||||
// Получаем текущие рубрики из меню
|
||||
$categories = get_categories_from_menu_exact_order('rubrics');
|
||||
|
||||
foreach ($categories as $category) {
|
||||
if ($category->slug === 'uncategorized') continue;
|
||||
|
||||
@@ -82,7 +82,12 @@ if (!empty($top_posts)) {
|
||||
|
||||
<?}
|
||||
|
||||
}
|
||||
}?>
|
||||
|
||||
<div class="most-read__link">
|
||||
<a href="https://agroexpert.press/all-events/" class="most-read__link-inner text-13 link-icon-after">
|
||||
Все новости
|
||||
</a>
|
||||
</div>
|
||||
|
||||
}?>
|
||||
<?}?>
|
||||
|
||||
59
partials/rubrics-mobile-menu.php
Normal file
59
partials/rubrics-mobile-menu.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?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>
|
||||
Reference in New Issue
Block a user