This repository has been archived on 2024-04-03. You can view files and clone it, but cannot push or open issues or pull requests.
kspace-wordpress-theme/functions/cat-template.php

30 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2023-05-20 12:02:34 +02:00
<?php
// Use a parent category slug if it exists
function child_force_category_template($template) {
$cat = get_query_var('cat');
$category = get_category($cat);
if ( file_exists(TEMPLATEPATH . '/category-' . $category->cat_ID . '.php') ) {
$cat_template = TEMPLATEPATH . '/category-' . $category ->cat_ID . '.php';
} elseif ( file_exists(TEMPLATEPATH . '/category-' . $category->slug . '.php') ) {
$cat_template = TEMPLATEPATH . '/category-' . $category ->slug . '.php';
} elseif ( file_exists(TEMPLATEPATH . '/category-' . $category->category_parent . '.php') ) {
$cat_template = TEMPLATEPATH . '/category-' . $category->category_parent . '.php';
} else {
// Get Parent Slug
$cat_parent = get_category($category->category_parent);
if ( file_exists(TEMPLATEPATH . '/category-' . $cat_parent->slug . '.php') ) {
$cat_template = TEMPLATEPATH . '/category-' . $cat_parent->slug . '.php';
} else {
$cat_template = $template;
}
}
return $cat_template;
}
add_action('category_template', 'child_force_category_template');
?>