Alternative front page template for the Genesis Framework--to allow a static home page with optional widget areas.
<?php | |
/** | |
* Front Page template for Robin Works theme. Optionally adds widget areas to be used in addition | |
* to a static home page. | |
* | |
* | |
* @author Robin Cornett | |
* @license GPL-2.0+ | |
* @link http://robincornett.com/ | |
*/ | |
add_action( 'genesis_meta', 'robin_works_front_page_meta' ); | |
function robin_works_front_page_meta() { | |
if ( is_active_sidebar( 'home-top' ) || ( ( is_active_sidebar( 'home-left' ) && is_active_sidebar( 'home-right' ) ) ) ) { // check for active home widgets. if using right/left, both must have content. for balance. | |
if ( is_singular() ) { // check if the home page is a static page | |
remove_action( 'genesis_entry_header', 'genesis_do_post_title' ); // if it is, remove the page title. | |
add_action( 'genesis_entry_header', 'robin_works_home_featured_image' ); // if it is, display the featured image in the page header | |
} | |
else { | |
remove_action( 'genesis_loop', 'genesis_do_loop' ); // if it's not a static page and widget areas are active, remove the loop (latest posts) | |
} | |
add_action( 'genesis_loop', 'robin_works_home_widgets' ); // regardless, show the widgets. | |
} | |
} | |
function robin_works_home_featured_image() { // display the featured image for the front page. Large, please. | |
global $post; | |
$image = get_the_post_thumbnail( $post->ID, 'original', array( 'alt' => the_title_attribute( 'echo=0' ), 'title' => the_title_attribute( 'echo=0' ) ) ); | |
echo $image; | |
} | |
function robin_works_home_widgets() { | |
if ( is_active_sidebar( 'home-top' ) ) { | |
echo '<div class="home-top">'; | |
genesis_widget_area( 'home-top' ); | |
echo '</div>'; | |
} | |
if ( is_active_sidebar( 'home-left' ) && is_active_sidebar( 'home-right' ) ) { // both left and right widget areas need to have content. balance. | |
echo '<div class="home-left one-half first">'; | |
genesis_widget_area( 'home-left' ); | |
echo '</div>'; | |
echo '<div class="home-right one-half">'; | |
genesis_widget_area( 'home-right' ); | |
echo '</div>'; | |
} | |
} | |
genesis(); |
<?php | |
// Do not include the opening php tag! Add this code to your functions.php file. | |
/** Register widget areas */ | |
genesis_register_sidebar( array( | |
'id' => 'home-top', | |
'name' => __( 'Home Top', 'robin-works' ), | |
'description' => __( 'This is the home top section.', 'robin-works' ), | |
) ); | |
genesis_register_sidebar( array( | |
'id' => 'home-left', | |
'name' => __( 'Home Left', 'robin-works' ), | |
'description' => __( 'This is the home left section.', 'robin-works' ), | |
) ); | |
genesis_register_sidebar( array( | |
'id' => 'home-right', | |
'name' => __( 'Home Right', 'robin-works' ), | |
'description' => __( 'This is the home right section.', 'robin-works' ), | |
) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment