Are you missing something like this:
<img src="<?php echo $hdrimg; ?>" />
before the </div>
Thread Starter
macart
(@macart)
I tried, doesn’t work. Will this code only work in a header.php file? New to this, so not sure of all things wordpress yet.
<div id="contentBanner"><?php if (is_page('home') ) {
$hdrimg = 'home.jpg';} elseif ( is_page('store') ) {
$hdrimg = 'store.jpg';} elseif ( is_page('about') ) {
$hdrimg = 'about.jpg';} elseif ( is_page('gallery') ) {
$hdrimg = 'gallery.jpg';} elseif ( is_page('hidden') ) {
$hdrimg = 'hidden.jpg';} ?><img src="<?php echo $hdrimg; ?>" /></div>
Thread Starter
macart
(@macart)
Tried this also doesn’t work. Does this also need to have a function, not clear in the codex to me?
<div id="contentBanner"><?php
if ( is_page('about') || $post->post_parent == '2' ) {
// the page is "About", or the parent of the page is "About"
$contentBannerimg = 'about.jpg';
} else {
$contentBannerimg = 'home.jpg'; // just in case we are at an unclassified page, perhaps the home page
}
?>
</div>
If you change the first line:
if (is_page('home') )' to 'if (is_home() )
… and for testing purposes change the line:
<img src="<?php echo $hdrimg; ?>" />' to '<?php echo $hdrimg; ?>
… you should see text being written to the screen showing the file name depending on the page you are viewing. (I just tested this myself to verify.) This will get your placement set.
Next check where the images you want to display are being stored. You may need to modify the ‘<img src=”<?php echo $hdrimg; ?>” />’ line to use the correct path to them.
Perhaps something along the lines of:
<img src="<?php echo bloginfo('template_directory') . '/images/' . $hdrimg; ?>" />
Thread Starter
macart
(@macart)
Excellent Thank You! Only issue is blog page is loading home.jpg instead of blog.jpg. Any ideas?
<div id="contentBanner"><?php if (is_home() ) {
$hdrimg = 'home.jpg';} elseif ( is_page('store') ) {
$hdrimg = 'store.jpg';} elseif ( is_page('about') ) {
$hdrimg = 'about.jpg';} elseif ( is_page('gallery') ) {
$hdrimg = 'gallery.jpg';} elseif ( is_page('blog') ) {
$hdrimg = 'blog.jpg';} elseif ( is_page('hidden') ) {
$hdrimg = 'hidden.jpg';} ?><img src="<?php echo bloginfo('template_directory') . '/images/' . $hdrimg; ?>" /></div>
Have you thought about using Flutter? flutter.freshout.us/ it will allow you to add images to specific pages as part of its system.
so there’s no need for hard coding “if” statements, just echo get_img(‘image_name’) which pulls the image you set for that page.
full info is on their site
Thread Starter
macart
(@macart)
I tried changing my code to page #’s, blog page is still loading home.jpg instead of blog.jpg.
<div id="contentBanner"><?php if (is_home('3') ) {
$hdrimg = 'home.jpg';} elseif ( is_page('5') ) {
$hdrimg = 'store.jpg';} elseif ( is_page('2') ) {
$hdrimg = 'about.jpg';} elseif ( is_page('8') ) {
$hdrimg = 'gallery.jpg';} elseif ( is_page('10') ) {
$hdrimg = 'blog.jpg';} elseif ( is_page('12') ) {
$hdrimg = 'hidden.jpg';} ?><img src="<?php echo bloginfo('template_directory') . '/images/' . $hdrimg; ?>" /></div>
If you have a page named ‘blog’ … no, otherwise I imagine its defaulting to ‘home’. I do not see anything in the is_page() conditional to indicate anything special for ‘blog’.
The specifics of the function can be found on this page: http://core.trac.wordpress.org/browser/trunk/wp-includes/query.php
(search for ‘is_page’ … see around ‘line 387’)
The codex for is_page() is here: http://codex.wordpress.org/Function_Reference/is_page
Thread Starter
macart
(@macart)
Yes I have a page named blog, that is my page for posts.
<div id=”contentBanner”><?php if (is_home() ) {
$hdrimg = ‘home.jpg’;} elseif ( is_page(‘store’) ) {
$hdrimg = ‘store.jpg’;} elseif ( is_page(‘about’) ) {
$hdrimg = ‘about.jpg’;} elseif ( is_page(‘gallery’) ) {
$hdrimg = ‘gallery.jpg’;} elseif ( is_page(‘blog’) ) {
$hdrimg = ‘blog.jpg’;} elseif ( is_page(‘hidden’) ) {
$hdrimg = ‘hidden.jpg’;} ?><img src=”<?php echo bloginfo(‘template_directory’) . ‘/images/’ . $hdrimg; ?>” /></div>
Thread Starter
macart
(@macart)
I don’t know if this is correct, but fixed it for the moment.
<div id="contentBanner"><?php if (is_front_page() ) {
$hdrimg = 'home.jpg';} elseif ( is_page('store') ) {
$hdrimg = 'store.jpg';} elseif ( is_page('about') ) {
$hdrimg = 'about.jpg';} elseif ( is_page('gallery') ) {
$hdrimg = 'gallery.jpg';} elseif ( is_home('blog') ) {
$hdrimg = 'blog.jpg';} elseif ( is_page('hidden') ) {
$hdrimg = 'hidden.jpg';} ?><img src="<?php echo bloginfo('template_directory') . '/images/' . $hdrimg; ?>" /></div>
If you are still having problems making a distinction between the Home page and the Blog page, this might help:
http://blog.dt.org/index.php/2009/08/how-to-detect-the-front-home-page-of-a-wordpress-blog/