Свежие отраслевые новости на нашем канале в Telegram
-Добавьте «Ветеринарию и жизнь» в избранное в ЯНДЕКС.НОВОСТИ
+diff --git a/category-vystavki-i-konferenitsii.php b/category-61.php similarity index 100% rename from category-vystavki-i-konferenitsii.php rename to category-61.php diff --git a/functions.php b/functions.php index 5a78cd3..8ad7bc1 100644 --- a/functions.php +++ b/functions.php @@ -50,18 +50,54 @@ function mob_block($template){ } +//свой шаблон для категории +add_filter('category_template', function (){ + + $category = get_queried_object(); + $parent_id = $category->category_parent; // ID родителя + + $template = array(); //массив для поиска шаблонов + + $templates[] = "category-{$category->slug}.php"; + $templates[] = "category-{$category->term_id}.php"; + + if ($parent_id > 0){ + + $parent = get_category($parent_id); + $templates[] = "category-{$parent->slug}.php"; + $templates[] = "category-{$parent->term_id}.php"; + + } + + $templates[] = 'category.php'; + + return locate_template($templates); + + +}); + + //свой шаблон для категории add_filter( 'single_template', function ( $single_template ) { - + + $category = (array) get_the_category(); - foreach( (array) get_the_category() as $cat ) { - - if ( file_exists(TEMPLATEPATH . "/single-{$cat->slug}.php") ) - return TEMPLATEPATH . "/single-{$cat->slug}.php"; - - } - - return $single_template; + foreach( $category as $cat ) { + + if ( file_exists(TEMPLATEPATH . "/single-{$cat->term_id}.php") ){ + return TEMPLATEPATH . "/single-{$cat->term_id}.php"; + } + + $parent_id = $cat->parent; // шаблон гл рубрики + + if ($parent_id > 0){ + $parent = get_category($parent_id); + if (file_exists(TEMPLATEPATH . "/single-{$parent->term_id}.php") ) + return TEMPLATEPATH . "/single-{$parent->term_id}.php"; + } + + } + return $single_template; }, PHP_INT_MAX, 2 ); diff --git a/header.php b/header.php index ed4db6c..7bfe1ef 100644 --- a/header.php +++ b/header.php @@ -4,7 +4,7 @@
Свежие отраслевые новости на нашем канале в Telegram
-Добавьте «Ветеринарию и жизнь» в избранное в ЯНДЕКС.НОВОСТИ
+Свежие отраслевые новости на нашем канале в Telegram
+Добавьте «Ветеринарию и жизнь» в избранное в ЯНДЕКС.НОВОСТИ
+