tema
This commit is contained in:
56
wp-content/themes/sevastopol-tort-child/inc/routes.php
Normal file
56
wp-content/themes/sevastopol-tort-child/inc/routes.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
add_action( 'init', 'sev_tort_register_rewrite_rules' );
|
||||
function sev_tort_register_rewrite_rules() {
|
||||
foreach ( sev_tort_pages() as $slug => $page ) {
|
||||
add_rewrite_rule( '^' . preg_quote( $slug, '/' ) . '/?$', 'index.php?sev_tort_page=' . $slug, 'top' );
|
||||
}
|
||||
}
|
||||
|
||||
add_filter( 'query_vars', 'sev_tort_query_vars' );
|
||||
function sev_tort_query_vars( $vars ) {
|
||||
$vars[] = 'sev_tort_page';
|
||||
return $vars;
|
||||
}
|
||||
|
||||
add_action( 'template_redirect', 'sev_tort_route_status' );
|
||||
function sev_tort_route_status() {
|
||||
if ( sev_tort_current_page_config() ) {
|
||||
status_header( 200 );
|
||||
}
|
||||
}
|
||||
|
||||
add_filter( 'template_include', 'sev_tort_template_include' );
|
||||
function sev_tort_template_include( $template ) {
|
||||
$page = sev_tort_current_page_config();
|
||||
|
||||
if ( ! $page ) {
|
||||
return $template;
|
||||
}
|
||||
|
||||
if ( 'politika-konfidencialnosti' === $page['slug'] ) {
|
||||
return get_stylesheet_directory() . '/page-templates/page-policy.php';
|
||||
}
|
||||
|
||||
return get_stylesheet_directory() . '/page-templates/page-service.php';
|
||||
}
|
||||
|
||||
function sev_tort_current_page_config() {
|
||||
$slug = get_query_var( 'sev_tort_page' );
|
||||
|
||||
if ( ! $slug && is_front_page() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! $slug && is_page() ) {
|
||||
$slug = get_post_field( 'post_name', get_queried_object_id() );
|
||||
}
|
||||
|
||||
$pages = sev_tort_pages();
|
||||
|
||||
return isset( $pages[ $slug ] ) ? $pages[ $slug ] : false;
|
||||
}
|
||||
Reference in New Issue
Block a user