Here’s a growing collection of code snippets I find useful.
Enable the Post Thumbnail Feature
Post thumbnails were added in WordPress 2.9. Justin Tadlock has a great article about this. To enable the feature in your theme, simply add this code snippet to the functions.php file:
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
}
To Use Post Thumbnails
<?php the_post_thumbnail( 'thumbnail' ); ?> <?php the_post_thumbnail( 'medium' ); ?> <?php the_post_thumbnail( 'full' ); ?>
Get the Post Name
This function is great if you need to style a certain element differently from page to page.
<div class="<?php echo $post->post_name; ?>"> </div>
Thanks for this: Post thumbnails are fantastic and I was just going to dive in and learn how to use them!