start special project FOREST
This commit is contained in:
@@ -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;
|
||||
});
|
||||
Reference in New Issue
Block a user