Skip to content

Instantly share code, notes, and snippets.

@KarasAlina
Created July 27, 2016 10:37
Show Gist options
  • Save KarasAlina/5d5ce2e5e2cb4e7073efa81c35a48e1c to your computer and use it in GitHub Desktop.
Save KarasAlina/5d5ce2e5e2cb4e7073efa81c35a48e1c to your computer and use it in GitHub Desktop.
Использование шаблона родительских рубрик для дочерних. Слаг у родительской рубрики надо указать такой же как и слаг у файла category-_____.php
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