• nickybc

    (@nickybc)


    Hi there, Im using the following code to display a different header on each of my wordpress pages:

    <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>

    To insert a new header image I am calling “banner” within a page’s custom fields.

    However, it doesn’t seem to work for posts as well. I have tried calling “banner” from inside my posts, but still nothing. I was just wondering if anyone knew how to adapt the code to include a custom header within posts as well. I would be very gratefull for your help.

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • MichaelH

    (@michaelh)

    The value of $post->ID may not be set…

    If you are talking about a Page then $posts[0]->ID might be the ticket.

    You might also want to use get_the_title($posts[0]->ID); for the title.

    Thread Starter nickybc

    (@nickybc)

    Hey, thanks for the reply!

    The custom headers are showing up fine on all of my “Pages”, just not on any “posts”, my navigation just moves up like nothing is there. So I am assuming nothing is being inserted.

    How would I go about setting the value of “$post->ID” ? I am very new to php, so go easy on me!

    Thanks

    MichaelH

    (@michaelh)

    Well you will have to review Template Hierarchy because a display of posts could involve many posts or just one post. You don’t set the value of $post->ID, WordPress does that if using a loop structure.

    Related:
    Stepping Into Template Tags
    Stepping Into Templates

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Header on Posts Page Not Working’ is closed to new replies.