Skip to content

Instantly share code, notes, and snippets.

@sxidsvit
Last active December 12, 2017 08:15
Show Gist options
  • Select an option

  • Save sxidsvit/3e90cf6f689ac7718a3d83b8cc94c7b6 to your computer and use it in GitHub Desktop.

Select an option

Save sxidsvit/3e90cf6f689ac7718a3d83b8cc94c7b6 to your computer and use it in GitHub Desktop.
Выбор шаблона для элементов/термов заданной таксономии
<?php
/*
Идущий НИЖЕ код можно вставить в файл custom_functions.php или ВЕСЬ файл подключить в custom_functions.php, используя код
if(file_exists(dirname( __FILE__ ).'/select_product_cat_template.php')){ include_once 'select_product_cat_template.php'; }
*/
add_action('template_redirect', 'select_product_cat_template');
function select_product_cat_template() {
/*
WP_Term Object
(
[term_id] => 22
[name] => Категория 1
[slug] => cat_1
[term_group] => 0
[term_taxonomy_id] => 22
[taxonomy] => product_cat
[description] =>
[parent] => 0
[count] => 4
[filter] => raw
)
*/
if (is_tax('product_cat')): // product_cat - название/терм/слаг таксономии
$queried_object = get_queried_object();
while ($queried_object->slug) {
if ( file_exists(TEMPLATEPATH . "/archive-product-" . $queried_object->slug . '.php') ) {
include(TEMPLATEPATH . "/archive-product-" . $queried_object->slug . '.php');
exit;
}
include(TEMPLATEPATH . "/archive-product.php"); // Если подходящего шаблона нет
}
endif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment