Community Forums › Forums › Archived Forums › Design Tips and Tricks › Got header banner Image on pages, but doesn't appear on blog?
Tagged: Banner image, blog header, header image
- This topic has 7 replies, 3 voices, and was last updated 9 years, 2 months ago by chobs.
-
AuthorPosts
-
February 19, 2015 at 7:24 am #141293chobsMember
I added a header image on pages however when I specify a single page for 'blog' the header disappears. Here's what I have:
//* Add Header Images on Pages add_image_size( 'header-img', 1600); add_action('genesis_after_header', 'site_banner', 0); function site_banner(){ if( !is_singular('page') ) return; if( has_post_thumbnail() && is_page() ) : $ftbanner = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'header-img' ); $banner = $ftbanner[0]; echo '<div id="site-banner" class="site-banner">' . "\n"; echo '<img src="' . $banner . '">' . "\n"; echo '</div>' . "\n"; endif; }
Thoughts?
February 19, 2015 at 8:11 am #141297Lauren @ OnceCoupledMemberI assume you're specifying
is_page('blog')
withinif( has_post_thumbnail() && is_page() ) :
? And this performs improperly, while other scenarios are working?Have you read through the documentation for http://codex.wordpress.org/Function_Reference/is_page? The parameter within
is_page()
needs to be Page ID, Page Title or Page Slug -- not the page template.Could be your problem -- hope it helps.
Best,
Lauren
We create mobile-first, PageSpeed-optimized, pixel-perfect custom themes! https://www.oncecoupled.com
February 19, 2015 at 8:36 am #141299chobsMemberThanks Lauren, sorry I'm not sure I follow. by specifying do you mean
if( has_post_thumbnail() && is_page('blog') ) :
?I read thru the codex, even added an ID:
if( has_post_thumbnail() && is_page(201) ) :
no dice. and maybe something else needs to change? I'm new at this so I appreciate your insight.
Thanks! c
February 19, 2015 at 8:51 am #141303Genesis DeveloperMemberCan you share the site URL?
February 19, 2015 at 8:59 am #141306chobsMemberIt's local I'm afraid. But thanks for jumping in.
c
February 19, 2015 at 9:53 am #141317chobsMemberOkay I got rid of the !isingular_page('page') and replaced it with is_home() and included an ID for the page in the second conditional. Thanks for the troubleshoot Lauren!
//* Add Header Images on Posts/Pages add_image_size( 'header-img', 1600); add_action('genesis_after_header', 'site_banner', 0); function site_banner(){ if( is_home() ) return; if( has_post_thumbnail() && is_page(201) ) : $ftbanner = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'header-img' ); $banner = $ftbanner[0]; echo '<div id="site-banner" class="site-banner">' . "\n"; echo '<img src="' . $banner . '">' . "\n"; echo '</div>' . "\n"; endif; }
February 19, 2015 at 1:12 pm #141352chobsMemberSpoke too soon, somehow this code still only specifies adding a banner image to the header of Pages -- I should probably mention I'm using the Parallax Pro theme which requires a Blog page be created in the Pages section for a blog roll to work. In any case the Blog is a page, yet it doesn't display like the other pages...my head hurts.
February 20, 2015 at 6:50 am #141434chobsMemberFor future coders: I got some help from Howdy_McGee at WP Stack Exchange, he made some suggestions that worked like a charm, basically WP was seeing single pages. Previously I was using !is_singular( 'page' ), however when I created a 'Blog' from a page, it automatically becomes an archive, so that rules out it being 'a single page' as it is now pulling in a lot of Blog posts and WP doesn't recognize it. And, there's no way to specify a page ID because of it. So we use is_page() and is_home() instead. And for the second conditional we use if is_home get page_for_posts and ask it to get_the_ID. Long story short, if you want a banner image on pages and posts drop this in your functions.php
//* Add Header Images on Posts/Pages add_image_size( 'header-img', 1600 ); add_action( 'genesis_after_header', 'site_banner', 0 ); function site_banner() { if( ( is_page() || is_home() ) ) { $post_id = ( is_home() ? get_option( 'page_for_posts' ) : get_the_ID() ); if( has_post_thumbnail( $post_id ) ) { $ftbanner = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'header-img' ); $banner = $ftbanner[0]; echo '<div id="site-banner" class="site-banner">' . "\n"; echo '<img src="' . $banner . '">' . "\n"; echo '</div>' . "\n"; } } }
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.