Created
May 18, 2014 15:44
-
-
Save JanHoek/997002ed9b86a08a3244 to your computer and use it in GitHub Desktop.
Create a Widget Area with Featured image as background for 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 // remove this line | |
// Register OnTop Widget | |
genesis_register_sidebar( array( | |
'id' => 'ontop', | |
'name' => __( 'OnTop', 'jan' ), | |
'description' => __( 'This the Ontop widget', 'jan' ), | |
) ); | |
// Adding option to use featured image (if it exists) | |
// as background image | |
add_image_size( 'featured-banner', 2000, 500, TRUE ); // creates a featured image size for the banner | |
function jan_featured_img() { | |
if ( has_post_thumbnail() ) { // checks post has thumbnail | |
// gets URL for that image | |
$background = wp_get_attachment_image_src( get_post_thumbnail_id( $page->ID ), 'featured-banner' ); | |
if (is_array($background)) { | |
// echo the output | |
echo '<div class="features" style="background: url(' ; | |
echo $background[0]; | |
echo ') no-repeat scroll center center #FFFFFF"><div class="wrap">'; | |
genesis_widget_area( 'ontop', array( | |
'before' => '<div class="features-widgetarea">', | |
'after' => '</div>', | |
) ); | |
echo '</div></div>'; | |
}} | |
else { // if no featured image, adds class to use default image | |
echo '<div class="features"><div class="wrap">'; | |
genesis_widget_area( 'ontop', array( | |
'before' => '<div class="features-widgetarea">', | |
'after' => '</div>', | |
) ); | |
echo '</div></div>'; | |
}} | |
add_action( 'genesis_after_header', 'jan_featured_img' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment