Wordpress Image Header for Each Post

29 views
asked Aug 16, 2012 in Website Builder by SunFun (3,000 points)
Hi there

I am trying to create a customized field where visitors can add images as headers for posts. I want it to work such as if there are no images to be added, the post should follow the standard title header.
Any help will be appreciated

Many thanks

2 Answers

0 like 0 dislike
answered Aug 18, 2012 by WebProX (12,200 points)
Try setting the header image as a featured image in a post and add the following code under your 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 you can display details of post individually.
0 like 0 dislike
answered Aug 18, 2012 by WebGuru (9,280 points)
if ( haspost_thumbnail() ) {
  post_thumbnail();
}
<h2 class="title"><?php the_title(); ?></h2>
...