add subtemplates and block promo smm

This commit is contained in:
arlemp@selectel.ru
2021-11-11 19:30:47 +03:00
parent 30b9d5c83c
commit 9aefc76b6e
6 changed files with 66 additions and 13 deletions

View File

@@ -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 );