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

69 lines
2.4 KiB

<?php
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 {
$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 {
$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/";
}
return $context;
});
?>