Viewing 3 replies - 1 through 3 (of 3 total)
  • Set the header image as featured image into post and write the following code under your single page template:

    global $post;
    $post_thumbnail_id = get_post_meta($post->ID, ‘featured_image’, true);
    if ($post_thumbnail_id > 0) {
    $attachment =& get_post($post_thumbnail_id);
    echo ‘<img src=”‘ . $attachment->guid . ‘” alt=”” />’;
    }

    Then display title or further details of individual post.

    You can use this too:

    if ( has_post_thumbnail() ) {
      the_post_thumbnail();
    }
    <h2 class="entry-title"><?php the_title(); ?></h2>

    Thread Starter AntonioAlmeida

    (@antonioalmeida)

    Thanks mate,
    Your help led me to this:

    loop-single.php

    <?php if (has_post_thumbnail() ) : ?>
    	<div id="post_header_img">
    	<h1 class="entry-title"><?php the_title(); ?></h1>
    	<div>
    
    <?php else :?>
    <?php endif; ?>
    
    	<h1 class="entry-title"><?php the_title(); ?></h1>
            <?the_post_thumbnail(); ?>

    It just weird how the <?the_post_thumbnail(); ?> has to be outside the if and else tag for the result I want… but it works.

    You can now view a post with a featured image and without.

    https://www.antoniodigitalmedia.com/2012/08/14/this-is-my-tuttle/
    https://www.antoniodigitalmedia.com/2012/08/14/225/

    Many thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Unique Header Image for Each Post (2)’ is closed to new replies.