Last active
December 12, 2017 08:15
-
-
Save sxidsvit/3e90cf6f689ac7718a3d83b8cc94c7b6 to your computer and use it in GitHub Desktop.
Выбор шаблона для элементов/термов заданной таксономии
This file contains hidden or 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
| <?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