
In a few days, WordPress 2.9 will be released. This all new version feature a bunch of interesting functions to display an image attached to a post.

In a few days, WordPress 2.9 will be released. This all new version feature a bunch of interesting functions to display an image attached to a post.
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.
13 Responses
Very useful, thanks a lot! =)
great tip! Thanks!
Uh oh… new version of wordpress.
Thanks, I use a lot of images on my sites so I might need this. I’ll have to see what damage WP 2.9 does first.
Wow thats Great. Thanks for this recipes. On my next Blog in feautre i need it because i want to work with more images.
THX
Thomas
Nice way of getting around any compatibility issues!
Don’t you need to place something in functions.php to get the post image uploader to be displayed in the post panel?
There has been a code change. You need to use the_post_thumbnail_*
Check dougal.gunters.org/blog/2009/12/11/post-thumbnails-changes
Trackbacks: