Forked from markjaquith/genesis-front-page-manager-functions.php
Last active
August 29, 2015 14:09
-
-
Save webdev1001/04ddfb42ed5d71adf2c6 to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** | |
* Genesis Front Page Manager | |
* | |
* @package Genesis_Front_Page_Manager | |
* @author Brad Potter | |
* @license GPL-2.0+ | |
* @link http://www.bradpotter.com/plugins/genesis-front-page-manager | |
* @copyright Copyright (c) 2014, Brad Potter | |
*/ | |
/** | |
* Add metabox for Front Page Manager | |
*/ | |
add_action( 'genesis_theme_settings_metaboxes', 'front_page_manager_metaboxes', 10, 1 ); | |
function front_page_manager_metaboxes( $pagehook ) { | |
add_meta_box( 'front-page-manager', __( 'Front Page Manager', 'genesis-front-page-manager' ), 'front_page_metabox', $pagehook, 'main', 'high' ); | |
} | |
/** | |
* Content for the Front Page Manager metabox | |
*/ | |
function front_page_metabox() { | |
// set the default selection (if empty) | |
$frontpageselect = genesis_get_option('front_page_select') ? genesis_get_option('front_page_select') : 'front-page.php'; | |
?> | |
<p> | |
<select name="<?php echo GENESIS_SETTINGS_FIELD; ?>[front_page_select]"> | |
<?php | |
foreach ( glob(CHILD_DIR . "/front-page*.php") as $file ) { | |
$file = str_replace( CHILD_DIR . '/', '', $file ); | |
?> | |
<option value="<?php echo esc_attr( $file ); ?>" <?php selected($file, $frontpageselect); ?>><?php echo esc_html( $file ); ?></option> | |
<?php } ?> | |
</select> | |
</p> | |
<p><span class="description">Select your desired <b>Front Page</b> from the drop down list and save your settings.</span></p> | |
<?php | |
} | |
/** | |
* Template Include | |
*/ | |
add_filter( 'template_include', 'front_page_manager_include' ); | |
function front_page_manager_include( $template ) { | |
if( is_home() || is_front_page() ) { | |
$frontpagemanager = genesis_get_option( 'front_page_select' ); | |
if ( $frontpagemanager && preg_match( '#^front-page-[a-z0-9-]+\.php$#', $frontpagemanager ) ) { | |
return $frontpagemanager; | |
} | |
} | |
return $template; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment