Last active
October 7, 2015 04:47
-
-
Save ramseyp/3107567 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 | |
/** | |
* Full-size Backgrounds using a Post Type of Background | |
* | |
* Function that selects a custom post type 'background'. | |
* Uses the Post Thumbnail as the background image. | |
* On the Page template(s) where it's needed, call s25_full_bg. | |
* | |
*/ | |
function s25_full_bg() { | |
// Build loop arguments for selecting Background | |
if ( !wp_is_mobile() ) { | |
$bgargs = array ( | |
'post_status' => 'publish', | |
'post_type' => 'background', | |
'orderby' => 'menu_order', | |
'posts_per_page' => 7, | |
); | |
// Loop that grabs a Background | |
$bg_loop = new WP_Query( $bgargs ); | |
if ( $bg_loop->have_posts() ) { | |
echo '<div id="bg_full">'; | |
while ( $bg_loop->have_posts() ) : $bg_loop->the_post(); | |
// Selects the post thumbnail from the Background and sets it as the fixed, full-width background image. | |
if ( has_post_thumbnail() ) { | |
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' ); | |
$obg_img = $thumb['0']; | |
} | |
echo '<div class="bg"><img src="'. $obg_img .'" alt="" /></div>'; | |
endwhile; | |
echo '</div><!-- close .bg_full -->'; | |
} | |
wp_reset_postdata(); | |
} | |
} | |
add_action ( 'genesis_before_header','s25_full_bg' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment