Files
agroexpert/inc/special.php

62 lines
2.2 KiB
PHP
Raw Normal View History

2025-05-29 00:59:59 +03:00
<?php
add_filter('category_template', function($template) {
2025-06-20 09:32:24 +03:00
if ( !is_category() ){
return $template;
}
2025-06-19 16:12:53 +03:00
2025-05-29 00:59:59 +03:00
$current_category = get_queried_object();
2025-06-19 16:12:53 +03:00
if ( $current_category->slug == 'rfo' ) {
$rfo_template = locate_template('rfo/landing.php');
if ($rfo_template) return $rfo_template;
}
2025-05-29 00:59:59 +03:00
// Только родительские рубрики (их дочерние подрубрики подхватятся автоматически)
$target_parent_slugs = ['forest', 'rfo']; // Только slug родительских рубрик
2025-06-19 16:12:53 +03:00
2025-05-29 00:59:59 +03:00
// Получаем родительскую рубрику
$parent_category = $current_category->parent
? get_category($current_category->parent)
: $current_category;
2025-06-16 00:24:13 +03:00
2025-05-29 00:59:59 +03:00
// Если текущая или родительская рубрика в списке
if (in_array($parent_category->slug, $target_parent_slugs)) {
$new_template = locate_template("category-{$parent_category->slug}.php");
if ($new_template) return $new_template;
}
2025-06-16 00:24:13 +03:00
2025-05-29 14:28:34 +03:00
return $template;
2025-06-19 16:12:53 +03:00
2025-05-29 14:28:34 +03:00
});
add_filter('single_template', function($template) {
global $post;
// Список целевых родительских рубрик (как в category_template)
$target_parent_slugs = ['forest', 'rfo'];
// Получаем все рубрики поста
$categories = get_the_category($post->ID);
if (empty($categories)) return $template;
// Проверяем каждую рубрику поста
foreach ($categories as $category) {
// Получаем родительскую рубрику (как в category_template)
$parent_category = $category->parent
? get_category($category->parent)
: $category;
// Если рубрика в списке целевых
2025-06-18 18:12:37 +03:00
if (in_array($parent_category->slug, $target_parent_slugs)) {
2025-05-29 14:28:34 +03:00
// Ищем шаблон single-{родительская-рубрика}.php
$new_template = locate_template("single-{$parent_category->slug}.php");
if ($new_template) return $new_template;
}
}
2025-05-29 00:59:59 +03:00
return $template;
});