Last active
May 6, 2019 15:05
-
-
Save eto4detak/0ff06ff62e02bc5b6695ee722fc0d7d1 to your computer and use it in GitHub Desktop.
wp php template
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 | |
## Какой шаблон используется в текущий момент | |
add_filter( 'template_include', 'echo_cur_tplfile', 99 ); | |
function echo_cur_tplfile( $template ){ | |
echo '<span style="color:red">'. wp_basename( $template ) .'</span>'; | |
return $template; | |
} | |
// | |
add_filter( 'template_include', 'sibl_template_include_404',99999999999 ); | |
function sibl_template_include_404( $template ){ | |
$url = $GLOBALS['_SERVER']['REDIRECT_URL']; | |
$urls_404 = ['/doma-bani/razmer-5x9/kJBCHnusUjY3ZRG/' | |
, '/category/srub-doma-iz-brevna-proekty/razmer-8x8/view-s_mansardoj/bcj44ky7tffxwm7/' | |
, '/category/srub-bani-iz-brevna-proekty/razmer-6x4/ftgt/' | |
]; | |
if(in_array($url, $urls_404)){ | |
return '/home/v/vasjalxm/sibles-stroi.com/public_html/wp-content/themes/sibl/404.php'; | |
} | |
return $template; | |
} | |
//` | |
add_filter( 'template_include', 'compare_template_loader' ); | |
function compare_template_loader( $template ) { | |
$auto_listing_page = false; | |
if(!empty(get_option('_pixad_autos_settings'))){ | |
$settings = unserialize( get_option( '_pixad_autos_settings' )); | |
$auto_listing_page = !empty($settings['autos_listing_car_page']) ? $settings['autos_listing_car_page'] : false ; | |
} | |
$object = get_queried_object(); | |
if ( is_embed() ) { | |
return $template; | |
} | |
if($object->ID == (int)$auto_listing_page){ | |
$template = locate_template('autos.php'); | |
} | |
return $template; | |
} | |
// получить урлы с шаблоном | |
$template_link = get_transient( 'wpestate_get_template_link_' . $transient_name ); | |
if( $template_link === false || $bypass==1 ) { | |
$pages = get_pages(array( | |
'meta_key' => '_wp_page_template', | |
'meta_value' => $template_name | |
)); | |
if( $pages ){ | |
$template_link = get_permalink( $pages[0]->ID ); | |
}else{ | |
$template_link=home_url(); | |
} | |
set_transient('wpestate_get_template_link_' . $transient_name,$template_link,60*60*24); | |
} | |
// создать страницы с шаблонами | |
add_action("after_switch_theme", "wp_estate_setup"); | |
if( !function_exists('wp_estate_setup') ): | |
function wp_estate_setup() { | |
$page_creation=array( | |
array( | |
'name' =>'Dashboard - Search Results', | |
'template' =>'user_dashboard_search_result.php', | |
), | |
array( | |
'name' =>'Dashboard - Saved Searches', | |
'template' =>'user_dashboard_searches.php', | |
), | |
); | |
foreach($page_creation as $key=>$template){ | |
if ( wpestate_get_template_link($template['template'],1 )==home_url() ){ | |
$my_post = array( | |
'post_title' => $template['name'], | |
'post_type' => 'page', | |
'post_status' => 'publish', | |
); | |
$new_id = wp_insert_post($my_post); | |
update_post_meta($new_id, '_wp_page_template', $template['template'] ); | |
} | |
} | |
} | |
endif; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment