diff --git a/wp-content/themes/cosmopet/temp-functions/menu-logic.php b/wp-content/themes/cosmopet/temp-functions/menu-logic.php index 72b628a..2ccad43 100644 --- a/wp-content/themes/cosmopet/temp-functions/menu-logic.php +++ b/wp-content/themes/cosmopet/temp-functions/menu-logic.php @@ -6,65 +6,12 @@ function register_custom_menus() { 'main-menu' => 'Основное меню', 'cats-menu' => 'Меню для кошек', 'dogs-menu' => 'Меню для собак', + 'mobile-menu' => 'Мобильное меню', ]); } add_action('after_setup_theme', 'register_custom_menus'); -class Custom_Walker_Nav_Menu 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 .= '
'; - $output .= '' . esc_html($item->title) . ''; - } else { - // Для дочерних элементов - $output .= '
  • '; - $output .= '' . esc_html($item->title) . ''; - } - } - - // Закрытие элемента меню - function end_el( &$output, $item, $depth = 0, $args = null, $id = 0 ) { - // Закрытие для родительского элемента - if ($depth === 0) { - $output .= '
  • '; // Закрытие .header-pc-menu__item - } else { - // Закрытие для дочернего элемента - $output .= ''; - } - } -} - - -function get_custom_menu($location) { - // Используем wp_nav_menu с нужными параметрами - ob_start(); // Начинаем буферизацию вывода - wp_nav_menu(array( - 'theme_location' => $location, - 'menu_class' => '', // Не добавляем класс к ul - 'container' => false, // Без контейнера - 'depth' => 2, // Уровень вложенности - 'walker' => new Custom_Walker_Nav_Menu(), // Используем кастомный walker - )); - $menu_html = ob_get_clean(); // Получаем HTML меню - - return $menu_html; -} - - - class Custom_Header_Phone_Menu_Walker extends Walker_Nav_Menu { // Открытие подменю (если есть) function start_lvl( &$output, $depth = 0, $args = null ) { @@ -100,8 +47,6 @@ class Custom_Header_Phone_Menu_Walker extends Walker_Nav_Menu { } } } - - // Функция для вызова меню и передачи HTML в Twig function get_custom_phone_menu($location = 'phone_menu') { ob_start(); // Начинаем буферизацию вывода @@ -115,4 +60,26 @@ function get_custom_phone_menu($location = 'phone_menu') { $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'); + $context['cat_menu'] = Timber::get_menu('cats-menu'); + $context['dog_menu'] = Timber::get_menu('dogs-menu'); + $context['mobile_menu'] = Timber::get_menu('mobile-menu'); + return $context; } \ No newline at end of file diff --git a/wp-content/themes/cosmopet/temp-functions/modules-logic.php b/wp-content/themes/cosmopet/temp-functions/modules-logic.php index 35f2ebb..022e834 100644 --- a/wp-content/themes/cosmopet/temp-functions/modules-logic.php +++ b/wp-content/themes/cosmopet/temp-functions/modules-logic.php @@ -336,7 +336,7 @@ include_module('layout'); add_action('wp', 'my_custom_checkout_code'); function my_custom_checkout_code() { - if (function_exists('is_checkout')) { + if (function_exists('is_checkout') && is_checkout()) { include_component('shop', 'checkout'); } } diff --git a/wp-content/themes/cosmopet/templates/header.twig b/wp-content/themes/cosmopet/templates/header.twig index cb93c1d..e405b54 100644 --- a/wp-content/themes/cosmopet/templates/header.twig +++ b/wp-content/themes/cosmopet/templates/header.twig @@ -8,63 +8,13 @@
    {# Кошки #} - {% set cat_menu = fn('get_custom_menu', 'cats-menu') %} - {{ cat_menu|raw }} + {% include 'menu/product-menu.twig' with {'child_menu': cat_menu} %} {# Собаки #} - {% set dog_menu = fn('get_custom_menu', 'dogs-menu') %} - {{ dog_menu|raw }} + {% include 'menu/product-menu.twig' with {'child_menu': dog_menu} %}
    -
    -
    - {% if current_lang == 'ru' %}ГЛАВНАЯ{% elseif current_lang == 'en' %}MAIN{% endif %} -
    - - {% if current_lang == 'ru' %} -
    - - ПРОДУКЦИЯ - - - {% set cat_m_menu = fn('get_custom_phone_menu', 'cats-menu') %} - {{ cat_m_menu|raw }} - {% set dog_m_menu = fn('get_custom_phone_menu', 'dogs-menu') %} - {{ dog_m_menu|raw }} -
    - {% elseif current_lang == 'en' %} -
    - - BUY - - {% set cat_m_menu = fn('get_custom_phone_menu', 'cats-menu') %} - {{ cat_m_menu|raw }} - {% set dog_m_menu = fn('get_custom_phone_menu', 'dogs-menu') %} - {{ dog_m_menu|raw }} -
    - {% endif %} - -
    - {% if current_lang == 'ru' %}О - COSMOPET{% elseif current_lang == 'en' %}ABOUT COSMOPET{% endif %} - -
    -
    - - {% if current_lang == 'ru' %}ПРОИЗВОДСТВО{% elseif current_lang == 'en' %}PRODUCTION{% endif %} - -
    - - {% if CONSTANTS.DOMAIN != 'AE' %} -
    - {% if current_lang == 'ru' %}БЛОГ{% elseif current_lang == 'en' %}BLOG{% endif %} -
    - {% endif %} -
    + {% include 'menu/mobile-menu.twig' %}
    - - + {% include 'menu/main-menu.twig' %}
    {% if site_region == 'ru' %} diff --git a/wp-content/themes/cosmopet/templates/menu/main-menu.twig b/wp-content/themes/cosmopet/templates/menu/main-menu.twig new file mode 100644 index 0000000..db56205 --- /dev/null +++ b/wp-content/themes/cosmopet/templates/menu/main-menu.twig @@ -0,0 +1,12 @@ + \ No newline at end of file diff --git a/wp-content/themes/cosmopet/templates/menu/mobile-menu.twig b/wp-content/themes/cosmopet/templates/menu/mobile-menu.twig new file mode 100644 index 0000000..f512f9b --- /dev/null +++ b/wp-content/themes/cosmopet/templates/menu/mobile-menu.twig @@ -0,0 +1,24 @@ +
    +{% for item in mobile_menu.items %} +
    + + {{ item.title }} + + {% if item.children %} + {% for child in item.children %} + {{ child.title }} + {% if child.children %} + + {% endif %} + {% endfor %} + {% endif %} +
    +{% endfor %} + +
    \ No newline at end of file diff --git a/wp-content/themes/cosmopet/templates/menu/product-menu.twig b/wp-content/themes/cosmopet/templates/menu/product-menu.twig new file mode 100644 index 0000000..1238d06 --- /dev/null +++ b/wp-content/themes/cosmopet/templates/menu/product-menu.twig @@ -0,0 +1,15 @@ +
    +{% for item in child_menu.items %} +{{ item.title }} +{% if item.children %} + +{% endif %} +{% endfor %} +
    +