From 64154c3dc58083490cbb8e2f4f1d8eace6e17664 Mon Sep 17 00:00:00 2001 From: argoexpert press Date: Sat, 10 May 2025 00:00:09 +0300 Subject: [PATCH] add new logic rubrics --- front-page.php | 2 +- functions.php | 2 + inc/rubrics-menu.php | 63 +++++++++++++++++++++++++ partials/category-menu-for-category.php | 12 +---- partials/category-menu.php | 11 +---- partials/most-read-posts.php | 9 +++- partials/rubrics-mobile-menu.php | 59 +++++++++++++++++++++++ 7 files changed, 136 insertions(+), 22 deletions(-) create mode 100644 inc/rubrics-menu.php create mode 100644 partials/rubrics-mobile-menu.php diff --git a/front-page.php b/front-page.php index 2084928..e364f87 100644 --- a/front-page.php +++ b/front-page.php @@ -2,7 +2,7 @@
- +
object === 'category') { + $category_ids[] = (int) $item->object_id; + } + } + + if (empty($category_ids)) return []; + + // Получение категорий + $terms = get_terms([ + 'taxonomy' => 'category', + 'include' => $category_ids, + 'hide_empty' => false, + ]); + + // Индексация по ID + $indexed = []; + foreach ($terms as $term) { + $indexed[$term->term_id] = $term; + } + + // Сортировка по порядку в меню + $ordered = []; + foreach ($category_ids as $id) { + if (isset($indexed[$id])) { + $ordered[] = $indexed[$id]; + } + } + + // Кэшируем результат + wp_cache_set($cache_key, $ordered, $cache_group); + + return $ordered; + +} + +//очищаем кеш при редактировании меню +add_action('wp_update_nav_menu', function($menu_id) { + $menu = wp_get_nav_menu_object($menu_id); + if ($menu && $menu->slug === 'rubrics') { + wp_cache_delete('categories_from_menu_rubrics', 'menu_categories'); + } +}); + + diff --git a/partials/category-menu-for-category.php b/partials/category-menu-for-category.php index 276becd..b0528f9 100644 --- a/partials/category-menu-for-category.php +++ b/partials/category-menu-for-category.php @@ -1,12 +1,7 @@ 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); diff --git a/partials/category-menu.php b/partials/category-menu.php index e2bfe63..183a4cc 100644 --- a/partials/category-menu.php +++ b/partials/category-menu.php @@ -1,14 +1,7 @@ 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; diff --git a/partials/most-read-posts.php b/partials/most-read-posts.php index 1e8da49..09102a1 100644 --- a/partials/most-read-posts.php +++ b/partials/most-read-posts.php @@ -82,7 +82,12 @@ if (!empty($top_posts)) { + -}?> + diff --git a/partials/rubrics-mobile-menu.php b/partials/rubrics-mobile-menu.php new file mode 100644 index 0000000..fb7becc --- /dev/null +++ b/partials/rubrics-mobile-menu.php @@ -0,0 +1,59 @@ +ID); +} elseif (is_category()) { + $current_term_ids[] = $current_term->term_id; +} + +?> + +