You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
cosmopet-architecture/wp-content/themes/cosmopet/modules/header/module-controller.php

92 lines
3.2 KiB

<?php
function header_enqueue_scripts() {
wp_enqueue_script( 'gp-header-script', get_template_directory_uri() . '/static/js/header.js', array(), null, true );
}
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;
});
?>