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.'&h=100&w=251&zc=1&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.











Loading ...
Hi Ciprian, thanks for this. Indeed, so easy!
Here I have another tutorial on how to make your first image post to be a thumbnail automatically without taking your time editing cropping thumbnail of your post.
Automatic WordPress Thumbnail Without Custom field and Featured image