This blog is NOFOLLOW Free!
  • INCEPTION THEME

    Clean, contrasting WordPress theme built on the foundation of Whiskey Air.
  • WHISKEY AIR THEME

    Clean developer theme, suited for heavy modifications.
  • X5 TURBO THEME

    3 columns Turbo theme, now reloaded!
  • CLEAR APPLE THEME

    Almost magazine theme, without the hassle of administration.

There are quite a handful of different post thumbnail solutions out there, but it seems that I found a very simple and compatible one that uses the famous timthumb library.

Add this code to your functions page, functions.php:


function post_image() {
 global $post, $posts;
 $thumb = '';
$output = preg_match_all('/ltimg.src'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
 $thumb = $matches [1] [0];

 if($thumb == '') { //Defines a default image or don't show at all. Use HTML inside the apostrophes.
 return '';
 }
 else {
return '<a href="'.get_permalink($post -> ID).'"><img src="http://www.tots2teens.ie/wp-content/themes/wp-tots/helpers/timthumb.php?src='.$thumb.'&amp;h=100&amp;w=251&amp;zc=1&amp;q=100" alt="" /></a>';
 }
}

Use <?php echo post_image();?> inside a custom defined loop to show the image. I did not bother to create a plugin as the solution is easier to be plugged in directly into functions.php.

See it in action here and here.

2 Responses to WordPress Automatic Post Thumbnail

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>