Last active
May 29, 2018 10:47
-
-
Save campusboy87/9f006a05dd3bb9e6655c8fa6b653fab2 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 | |
| /** | |
| * РАСПРЕДЕЛЕНИЕ ШАБЛОНОВ отображения контента в зависимости от раздела сайта | |
| * Данный файл создан, чтобы хранить шаблоны в стуктурированных папках и произвольными именами, а не в корне движка | |
| * | |
| * @param string $template серверная ссылка к шаблону по умолчанию | |
| * | |
| * @return string $template серверная ссылка к пользовательскому шаблону | |
| */ | |
| function jrst_tpl_path( $template ) { | |
| // Архивная страница типа поста "Юридические услуги" и "Недвижимость" | |
| if ( is_post_type_archive( [ 'yuridicheskie-uslugi', 'nedvizhimost-uslugi' ] ) ) { | |
| return jrst_locate_template( 'parts/category-legal-service.php' ); | |
| } | |
| // Архивная страница типа поста "Наши юристы" | |
| if ( is_post_type_archive( [ 'nashi-yuristy' ] ) ) { | |
| return jrst_locate_template( 'parts/nashi-yuristy__post-type-archive.php' ); | |
| } | |
| // Архивная страница типа поста "Выигранные дела" | |
| if ( is_post_type_archive( [ 'vyigrannye-dela' ] ) ) { | |
| return jrst_locate_template( 'parts/category-vyigrannye-dela.php' ); | |
| } | |
| // Рубрики | |
| if ( is_category() ) { | |
| // Новости | |
| if ( is_category( 'novosti' ) ) { | |
| return jrst_locate_template( 'parts/category-novosti.php' ); | |
| } | |
| return $template; | |
| } | |
| // Страницы | |
| if ( is_page() ) { | |
| // Наши парнеры | |
| if ( is_page( 'partners' ) ) { | |
| return jrst_locate_template( 'parts/page-partners.php' ); | |
| } | |
| // Благодарственные письма | |
| if ( is_page( 'blagodarstvennye-pisma' ) ) { | |
| return jrst_locate_template( 'parts/page-blagodarstvennye-pisma.php' ); | |
| } | |
| // Составление договоров | |
| if ( is_page( [ 'sostavlenie-dogovorov', 'vyezd-yurista' ] ) ) { | |
| return jrst_locate_template( 'parts/single-service.php' ); | |
| } | |
| // Отзывы | |
| if ( is_page( 'reviews' ) ) { | |
| return jrst_locate_template( 'parts/page-reviews.php' ); | |
| } | |
| // Контакты | |
| if ( is_page( 'kontakty' ) ) { | |
| return jrst_locate_template( 'parts/page-kontakty.php' ); | |
| } | |
| return $template; | |
| } | |
| // Тип постов Юридические услуги / Оформление недвижимости | |
| if ( is_singular( [ 'yuridicheskie-uslugi', 'nedvizhimost-uslugi' ] ) ) { | |
| return jrst_locate_template( 'parts/single-service.php' ); | |
| } | |
| // Тип постов Наши юристы | |
| if ( is_singular( [ 'nashi-yuristy' ] ) ) { | |
| return jrst_locate_template( 'parts/nashi-yuristy__single.php' ); | |
| } | |
| return $template; | |
| } | |
| add_filter( 'template_include', 'jrst_tpl_path', 99 ); | |
| /** | |
| * Упрощенная функция проверки и замены шаблона на пользовательский вариант | |
| * | |
| * @global string $template дефолтный путь к шаблону | |
| * | |
| * @param string $path пользовательский путь к шаблону | |
| * | |
| * @return string $template путь к шаблону | |
| */ | |
| function jrst_locate_template( $path ) { | |
| global $template; | |
| // Проверяем наличие файла шаблона по указанному пути | |
| if ( $new_template = locate_template( [ $path ] ) ) { | |
| $template = $new_template; | |
| } | |
| return $template; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment