From c37295ba6a353f1ef895a2ec7aae8e4414a22b29 Mon Sep 17 00:00:00 2001 From: maksim Date: Tue, 24 Jun 2025 10:48:24 +0300 Subject: [PATCH] =?UTF-8?q?Task=206875=20|=20=D0=9F=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=BD=D0=B5=D1=81=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D1=83=20?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=8E=20=D0=B2=20=D0=BE=D1=82=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB?= =?UTF-8?q?=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/header/module-controller.php | 84 +------------------ .../cosmopet/temp-functions/menu-logic.php | 62 -------------- .../themes/cosmopet/templates/header.twig | 5 -- 3 files changed, 1 insertion(+), 150 deletions(-) diff --git a/wp-content/themes/cosmopet/modules/header/module-controller.php b/wp-content/themes/cosmopet/modules/header/module-controller.php index b59c312..7fa57a8 100644 --- a/wp-content/themes/cosmopet/modules/header/module-controller.php +++ b/wp-content/themes/cosmopet/modules/header/module-controller.php @@ -5,88 +5,6 @@ function header_enqueue_scripts() { } add_action('wp_enqueue_scripts', 'header_enqueue_scripts'); -function is_home_page_posts_archive() { - // 1. Если главная страница - это страница записей - if (get_option('show_on_front') == 'posts') { - return true; - } - - // 2. Если главная - статическая страница, но выводит архив - if (get_option('show_on_front') == 'page') { - $front_page_id = get_option('page_on_front'); - // Проверяем, является ли это архивом - return is_post_type_archive_view($front_page_id); - } - - return false; -} - -// Дополнительная функция для проверки шаблона архива -function is_post_type_archive_view($page_id) { - $template = get_page_template_slug($page_id); - return strpos($template, 'archive') !== false || - strpos($template, 'blog') !== false; -} - - -add_filter('timber/context', function($context) { - // Проверяем существование страниц - $about_page = Timber::get_post([ - 'post_type' => 'page', - 'name' => 'o-kompanii', - 'limit' => 1 - ]); - - $production_page = Timber::get_post([ - 'post_type' => 'page', - 'name' => 'proizvodstvo', // Обратите внимание на возможную опечатку в slug - 'limit' => 1 - ]); - - // Устанавливаем URL для страницы "О компании" - if ($about_page) { - $context['about_url'] = '/o-kompanii/'; - $context['about_url_en'] = '/en/about-us/'; - } - else if (SITE_DOMAIN == 'AE'){ - $context['about_url_en'] = '/about-us/'; - } - else { - $context['about_url'] = 'https://cosmopet.shop/chto-takoe-entoprotein/'; - $context['about_url_en'] = 'https://cosmopet.shop/en/about-2/'; - } - - // Устанавливаем URL для страницы "Производство" - if ($production_page) { - $context['production_url'] = '/proizvodstvo/'; - $context['production_url_en'] = '/en/production/'; - } - else if (SITE_DOMAIN == 'AE'){ - $context['production_url_en'] = '/production/'; - } - else { - $context['production_url'] = 'https://cosmopet.shop/proizvodstvo/'; - $context['production_url_en'] = 'https://cosmopet.shop/en/production/'; - } - if (!is_home_page_posts_archive()) { - $context['front_url'] = "/"; - $context['front_url_en'] = "/en/main/"; - } - else{ - $context['front_url'] = "https://cosmopet.shop/"; - $context['front_url_en'] = "https://cosmopet.shop/en/main/"; - } - if (SITE_DOMAIN == 'AE'){ - $context['front_url_en'] = "/"; - } - - $current_language = pll_current_language(); // Получаем текущий язык - $menu_items = wp_get_nav_menu_items('main_menu_' . $current_language); // Получаем элементы меню для текущего языка - - $context['menu_items'] = $menu_items; - return $context; -}); - - +include_module('menu'); ?> \ No newline at end of file diff --git a/wp-content/themes/cosmopet/temp-functions/menu-logic.php b/wp-content/themes/cosmopet/temp-functions/menu-logic.php index 2ccad43..3f14281 100644 --- a/wp-content/themes/cosmopet/temp-functions/menu-logic.php +++ b/wp-content/themes/cosmopet/temp-functions/menu-logic.php @@ -11,70 +11,8 @@ function register_custom_menus() { } add_action('after_setup_theme', 'register_custom_menus'); - -class Custom_Header_Phone_Menu_Walker extends Walker_Nav_Menu { - // Открытие подменю (если есть) - function start_lvl( &$output, $depth = 0, $args = null ) { - $output .= ''; - } - - // Открытие элемента меню - function start_el( &$output, $item, $depth = 0, $args = null, $id = 0 ) { - if ($depth === 0) { - // Для родительского элемента - $output .= '' . esc_html($item->title) . ''; - } else { - // Для дочерних элементов - $output .= '
  • '; - $output .= '' . esc_html($item->title) . ''; - $output .= '
  • '; - } - } - - // Закрытие элемента меню - function end_el( &$output, $item, $depth = 0, $args = null, $id = 0 ) { - // Закрытие элемента на первом уровне (родительский элемент) - if ($depth === 0) { - // Пустое завершение для родительского элемента - } else { - // Закрытие для дочернего элемента - $output .= ''; - } - } -} -// Функция для вызова меню и передачи HTML в Twig -function get_custom_phone_menu($location = 'phone_menu') { - ob_start(); // Начинаем буферизацию вывода - wp_nav_menu(array( - 'theme_location' => $location, // Указываем местоположение меню - 'menu_class' => '', // Не добавляем класс к ul, он будет добавлен кастомно в walker - 'container' => false, // Без контейнера - 'depth' => 2, // Уровень вложенности (для отображения подменю) - 'walker' => new Custom_Header_Phone_Menu_Walker(), // Используем кастомный walker - )); - $menu_html = ob_get_clean(); // Получаем HTML меню - - return $menu_html; -} - - - - - - - add_filter('timber/context', 'add_to_context'); -/** - * Global Timber context. - * - * @param array $context Global context variables. - */ function add_to_context($context) { $context['main_menu'] = Timber::get_menu('main-menu'); diff --git a/wp-content/themes/cosmopet/templates/header.twig b/wp-content/themes/cosmopet/templates/header.twig index e405b54..0bfb836 100644 --- a/wp-content/themes/cosmopet/templates/header.twig +++ b/wp-content/themes/cosmopet/templates/header.twig @@ -1,8 +1,3 @@ -{# Получаем ID страницы блога из настроек #} -{% set posts_page_id = function('get_option', 'page_for_posts') %} - - -