• Resolved Lou

    (@purecreative)


    Hi,

    I am running the Twenty Ten theme and would like to set custom header image for different pages.

    I found the following code which, if I understand it correctly, puts a header image if one is called through the custom field value and leaves the space blank otherwise:

    <div class="banner"> <?php if(get_post_meta($post->ID, 'banner', true)) : ?> <img src="<?php echo get_post_meta($post->ID, 'banner', true); ?>" /> <?php else : ?> <?php the_title(); ?> <?php endif; ?> <div>

    This is almost what I need. I would like the code to look at the custom field value if there is one, and if there is none, leave the main banner up. Can it be done? If so, can someone please tell me how?

    This is the banner code in my twenty ten header.php file

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Thanks in advance for reading and for your help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Michael

    (@alchymyth)

    try to change this line:

    <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />

    into this section:

    <?php if(get_post_meta($post->ID, 'banner', true)) : ?> <img src="<?php echo get_post_meta($post->ID, 'banner', true); ?>" /> <?php else : ?>
    <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
    <?php endif; ?>

    Thread Starter Lou

    (@purecreative)

    That did it.

    Thanks, Sweeper!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘custom header for page’ is closed to new replies.