Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

On a site I'm designing (business site versus blog - static homepage, etc.) for a client I have 7 different top -level product/service pages which have the same layout except for a graphic that stretches across the top, below the horizontal navbar and above the page content. Everything up to and including the navbar will end up in the header.php.

I would like the graphic to be in the page template as opposed to being part of the page content that the clients could access via the TineMCE editor. I don't want to have to create 7 page templates just for different top graphics. Does that make sense?

I've come a long way with WP; I'm pretty solid with HTML and CSS but am a cutter/paster when I get to php, but I'm thinking I might be able to put some kind of if/then call in the page template basically saying "if service page, use servicehead.jpg; if customersupport page, use customerhead.jpg," etc.

Is this possible?

If so, could someone tell me how I would write the call?

Here is my current page.php code:

<?php get_header(); ?>
<div id="pagebg">
<div id="pageheads">
<img src="<?php bloginfo('template_url'); ?>/images/customerhead.jpg"
alt="" height="120" width="1020" border="0" /></div>
<div id="colL">

After the colL div I have the loop and then I call a sidebar and the footer.

I'm thinking I would put a call in the pageheads div?

Any help would be greatly appreciated!

Thanks!

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

You're looking for the function is_page() You could use the page id, the title or the slug in the function.

<?php if ( is_page('services') ) : ?>
<img...services
<?php elseif ( is_page('customer') ) : ?>
<img...customer
<?php else : ?>
<img..default
<?php endif; ?>

Another option is to use the post thumbnail feature from wordpress, then you can specify in the page which image you want on top (if you don't already use them). ( http://codex.wordpress.org/Post_Thumbnails )

share|improve this answer
    
Perfect! Exactly what i wanted -- the is_pages()-- it works beautifully! Thank You! –  PVA Jan 15 '12 at 19:18
add comment

You can do that using custom fields like so..

IN YOUR PAGE.PHP HEADER:

<?php
$key = 'headerIMG';
$themeta = get_post_meta($post->ID, $key, TRUE);
if($themeta = '') {
$themeta = 'DEFAULT IMG URL INCASE NO SPECIAL ONE EXIST';
}
?>

.
then where ever you want the image to show up:

<img src="<?php echo $themeta; ?>" alt="<?php the_title(); ?>" />

.
Last thing.. when ever you create a page with a speical image
you need to enter the value "headerIMG" in a custom field and the image URL as its value...

A Reminder:
please remmeber to replace the default img url in the first code
with the default one you want to show on pages without special images in the header unless there are none... (even so.. i would link to a default image just to be on the safe side)..

Hope this helps. Cheers, Sagive.

share|improve this answer
    
Sagive: thank you for your suggestion as well! –  PVA Jan 15 '12 at 19:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.