Fatal error: Call to undefined function the_post_image()
If you have recently downloaded the latest WordPress 2.9 beta build (like I have) you will find “the_post_image” no longer works! In place you will see that lovely “Fatal Error” message above.
“Post/Page Image was too generic a name. Post/Page Thumbnail is more clear, even if you can create very large thumbnail images if you so choose.”
Below, I will be noting the changes found in the latest build, and how to now use thumbnails in a WordPress theme using 2.9’s post thumbnail function.
Adding support for the post thumbnail feature in a theme
This part has not changed. Just add the code below to your themes function.php
if ( function_exists( 'add_theme_support' ) )
add_theme_support( 'post-thumbnails' );
So, what has changed?
the_post_image to the_post_thumbnail
old:
<?php the_post_image( 'thumbnail' ); ?>
New:
<?php the_post_thumbnail( 'thumbnail' ); ?>
<?php the_post_thumbnail( 'medium' ); ?>
<?php the_post_thumbnail( 'full' ); ?>
Checking if a post has an image
Old:
<?php
if ( has_post_image() )
the_post_image( 'thumbnail' );
else
echo '<img src="default-thumbnail.jpg" alt="Default Thumbnail" title="Default Thumbnail" />';
?>
New:
<?php
if ( has_post_thumbnail() )
the_post_thumbnail( 'thumbnail' );
else
echo '<img src="default-thumbnail.jpg" alt="Default Thumbnail" title="Default Thumbnail" />';
?>
Getting the post image ID
Old:
$image_id = get_post_image_id();
New:
$image_id = get_post_thumbnail_id();
This is a developing post…




4 Pings