Last active
August 29, 2015 14:04
-
-
Save robincornett/f6e4dfdba7eeaaac5682 to your computer and use it in GitHub Desktop.
Alternative front page template for the Genesis Framework--to allow a static home page with optional widget areas.
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 | |
/** | |
* 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(); |
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 | |
// 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' ), | |
) ); |
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
.home .entry { | |
padding: 0; | |
} | |
.home .entry-content { | |
padding: 40px; | |
} | |
.home-top, | |
.home-left, | |
.home-right { | |
background: #fff; | |
border-radius: 3px; | |
margin-bottom: 40px; | |
padding: 40px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment