mirror of
https://github.com/10h30/yeuchaybo.git
synced 2026-07-11 18:56:16 +09:00
118 lines
2.3 KiB
PHP
118 lines
2.3 KiB
PHP
<?php
|
|
/**
|
|
* Child Theme Library
|
|
*
|
|
* WARNING: This file is a part of the core Child Theme Library.
|
|
* DO NOT edit this file under any circumstances. Please use
|
|
* the functions.php file to make any theme modifications.
|
|
*
|
|
* @package SEOThemes\ChildThemeLibrary\Functions
|
|
* @link https://github.com/seothemes/child-theme-library
|
|
* @author Thuan Bui
|
|
* @copyright Copyright © 2018 Thuan Bui
|
|
* @license GPL-2.0+
|
|
*/
|
|
|
|
// If this file is called directly, abort.
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
add_filter( 'theme_page_templates', 'child_theme_add_page_templates' );
|
|
/**
|
|
* Add page templates.
|
|
*
|
|
* Removes default Genesis templates then loads library templates defined in
|
|
* the child theme's config file.
|
|
*
|
|
* @since 1.0.0
|
|
*
|
|
* @param array $page_templates The existing page templates.
|
|
*
|
|
* @return array
|
|
*/
|
|
function child_theme_add_page_templates( $page_templates ) {
|
|
|
|
$config = child_theme_get_config( 'page-templates' );
|
|
|
|
if ( array_key_exists( 'page-blog.php', $config ) ) {
|
|
|
|
unset( $config['page-blog.php'] );
|
|
|
|
} else {
|
|
|
|
unset( $page_templates['page_blog.php'] );
|
|
|
|
}
|
|
|
|
if ( array_key_exists( 'page-sitemap.php', $config ) ) {
|
|
|
|
unset( $page_templates['page_archive.php'] );
|
|
|
|
}
|
|
|
|
$page_templates = array_merge( $page_templates, $config );
|
|
|
|
return $page_templates;
|
|
|
|
}
|
|
|
|
add_filter( 'template_include', 'child_theme_set_page_template' );
|
|
/**
|
|
* Modify page based on selected page template.
|
|
*
|
|
* @since 1.0.0
|
|
*
|
|
* @param string $template The path to the template being included.
|
|
*
|
|
* @return string
|
|
*/
|
|
function child_theme_set_page_template( $template ) {
|
|
|
|
$config = child_theme_get_config( 'page-templates' );
|
|
|
|
if ( ! is_singular( 'page' ) ) {
|
|
|
|
return $template;
|
|
|
|
}
|
|
|
|
$current_template = get_post_meta( get_the_ID(), '_wp_page_template', true );
|
|
|
|
if ( 'page-blog.php' === $current_template ) {
|
|
|
|
$template = get_template_directory() . '/page_blog.php';
|
|
|
|
return $template;
|
|
|
|
}
|
|
|
|
if ( ! array_key_exists( $current_template, $config ) ) {
|
|
|
|
return $template;
|
|
|
|
}
|
|
|
|
$template_override = CHILD_THEME_DIR . '/templates/' . $current_template;
|
|
|
|
if ( file_exists( $template_override ) ) {
|
|
|
|
$template = $template_override;
|
|
|
|
} else {
|
|
|
|
$template_path = trailingslashit( CHILD_THEME_VIEWS ) . $current_template;
|
|
|
|
if ( file_exists( $template_path ) ) {
|
|
|
|
$template = $template_path;
|
|
|
|
}
|
|
}
|
|
|
|
return $template;
|
|
|
|
}
|