start special project FOREST

This commit is contained in:
argoexpert press
2025-05-29 14:28:34 +03:00
parent 1b83816191
commit 8596dd84bb
9 changed files with 235 additions and 7 deletions

View File

@@ -17,5 +17,33 @@ add_filter('category_template', function($template) {
if ($new_template) return $new_template;
}
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;
}
}
return $template;
});