WordPress 2.9 : Display post image with backward compatibility
by Jean-Baptiste Jung on November 23, 2009
Paste the following code, within the loop, where you want to post image to be displayed.
<?php
if ( (function_exists('has_post_image')) && (has_post_image()) ) {
the_post_image('thumbnail');
} else {
$postimageurl = get_post_meta($post->ID, 'post-image', true);
if ($postimageurl) {
echo '<img src="'.$postimageurl.'" alt="" />';
}
}
?>
What this code do :
-First, it makes sure that the has_post_image() function exists and that the current post have an image attached. If both conditions are true, the post image is displayed using WordPress 2.9 function the_post_image().
-If not, the get_post_meta() function is used to get the value of the custom field which contain the post image.
Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!
WordPress 2.9 : Display post image with backward compatibility