Created
July 27, 2016 10:37
-
-
Save KarasAlina/5d5ce2e5e2cb4e7073efa81c35a48e1c to your computer and use it in GitHub Desktop.
Использование шаблона родительских рубрик для дочерних. Слаг у родительской рубрики надо указать такой же как и слаг у файла category-_____.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action('template_redirect', 'wpds_parent_category_template'); | |
function wpds_parent_category_template() | |
{ | |
if (!is_category()) | |
return true; | |
// получаем объект текущей рубрики | |
$cat = get_category(get_query_var('cat')); | |
while ($cat && !is_wp_error($cat)) { | |
$template = TEMPLATEPATH . "/category-{$cat->slug}.php"; | |
// загружаем, если файл шаблона существует. | |
if (file_exists($template)) { | |
load_template($template); | |
exit; | |
} | |
$cat = $cat->parent ? get_category($cat->parent) : false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment