Files
yeuchaybo/lib/functions/layout.php
T
Thuan Bui fd25f13a4f Initial
2018-06-26 11:09:22 +07:00

143 lines
2.8 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_action( 'after_setup_theme', 'child_theme_add_layouts' );
/**
* Add theme layouts.
*
* @since 1.0.0
*
* @return void
*/
function child_theme_add_layouts() {
$config = child_theme_get_config( 'layouts' );
$initial_layouts = array(
'full-width-content',
'content-sidebar',
'sidebar-content',
'content-sidebar-sidebar',
'sidebar-sidebar-content',
'sidebar-content-sidebar',
);
$layouts_to_remove = array_diff( $initial_layouts, $config );
$custom_layouts = array_diff( $config, $initial_layouts );
foreach ( $layouts_to_remove as $layout_to_remove ) {
genesis_unregister_layout( $layout_to_remove );
}
foreach ( $custom_layouts as $custom_layout ) {
genesis_register_layout( $custom_layout, array(
'label' => ucwords( str_replace( '-', ' ', $custom_layout ) ),
'img' => CHILD_THEME_ASSETS . '/images/' . $custom_layout . '.gif',
) );
}
}
add_filter( 'genesis_site_layout', 'child_theme_search_page_layout' );
/**
* Gets a custom page layout for the search results page.
*
* @since 1.0.0
*
* @param string $layout Layout to return.
*
* @return string
*/
function child_theme_search_page_layout( $layout ) {
if ( is_search() ) {
$page = get_page_by_path( 'search' );
if ( $page ) {
$field = genesis_get_custom_field( '_genesis_layout', $page->ID );
$layout = $field ? $field : genesis_get_option( 'site_layout' );
}
}
return $layout;
}
add_filter( 'genesis_site_layout', 'child_theme_error_404_page_layout' );
/**
* Gets a custom page layout for the error 404 page.
*
* @since 1.0.0
*
* @param string $layout Layout to return.
*
* @return string
*/
function child_theme_error_404_page_layout( $layout ) {
if ( is_404() ) {
$page = get_page_by_path( 'error-404' );
if ( $page ) {
$field = genesis_get_custom_field( '_genesis_layout', $page->ID );
$layout = $field ? $field : genesis_get_option( 'site_layout' );
}
}
return $layout;
}
add_action( 'genesis_before', 'child_theme_remove_narrow_sidebars' );
/**
* Remove sidebars for narrow layout.
*
* @since 1.0.0
*
* @return void
*/
function child_theme_remove_narrow_sidebars() {
$site_layout = genesis_site_layout();
if ( 'center-content' !== $site_layout ) {
return;
}
add_filter( 'genesis_site_layout', '__genesis_return_full_width_content' );
}