2025-05-29 00:59:59 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
add_filter('category_template', function($template) {
|
|
|
|
|
$current_category = get_queried_object();
|
|
|
|
|
|
|
|
|
|
// Только родительские рубрики (их дочерние подрубрики подхватятся автоматически)
|
|
|
|
|
$target_parent_slugs = ['forest', 'rfo']; // Только slug родительских рубрик
|
|
|
|
|
|
|
|
|
|
// Получаем родительскую рубрику
|
|
|
|
|
$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;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
// Если рубрика в списке целевых
|
|
|
|
|
if (in_array($parent_category->slug, $target_parent_slugs)) {
|
|
|
|
|
// Ищем шаблон 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;
|
|
|
|
|
});
|