slug == 'rfo' ) { $rfo_template = locate_template('rfo/landing.php'); if ($rfo_template) return $rfo_template; } // Только родительские рубрики (их дочерние подрубрики подхватятся автоматически) $target_parent_slugs = ['forest', 'rfo']; // Только slug родительских рубрик // Получаем родительскую рубрику $parent_category = $current_category->parent ? get_category($current_category->parent) : $current_category; // Если текущая или родительская рубрика в списке if (in_array($parent_category->slug, $target_parent_slugs)) { $new_template = locate_template("category-{$parent_category->slug}.php"); 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; });