WordPress 2.9 add_theme_support and has_post_image

The new the_post_image functionality in WordPress version 2.9 has been enhanced.
New is the wp-settings.php line

// Load in support for template functions which the theme supports
require_if_theme_supports( 'post-thumbnails', ABSPATH . WPINC . '/post-image-template.php' );

In functions.php it queries whether the theme supports post-thumbnail function:

if ( function_exists( 'add_theme_support' ) )
	add_theme_support( 'post-thumbnails' );

If you look at the file wp-includes/post-image-template.php, there are 4 new features:

  • has_post_image()
  • get_post_image_id()
  • the_post_image()
  • get_the_post_image()

The theme itself can check within the loop, if the post has a Post-Thumbnail, and if so, then it can be output:

<?php if ( has_post_image() ) : ?>
	<a href="<?php the_permalink(); ?>"><?php the_post_image( array( 75, 75 ), array( 'class' => 'alignleft' ) ); ?></a>
<?php endif; ?>

Those interested in more features and information should check the file in WordPress 2.9: wp-includes/post-image-template.php
Especially the function: get_the_post_image
It allows to adjust the output by using hooks.
In get_the_post_image the function wp_get_attachment_image get also used, what has been explained in detail in this post just a few days ago.

Comments are closed.

4 comments

  1. Indrek

    Nice feature. Can't wait to start using it.

  2. Radu

    I've made a plugin (an update) related to this topic. I would like to share with you and get your opinion since it's unique and ready for WP 2.9. Please send me an email (and delete, eventualy this comment).

  3. Ryan

    Just a heads up for anyone reading this:

    has_post_image() and the_post_image()
    are now:
    has_post_thumbnail() and the_post_thumbnail()

    Make sure you change those function names before upgrading or your site will break.

One pingback

  1. WordPress 2.9 a chystané novinky (1): Náhledové obrázky | Separatista