If your theme is not a complicated one, you don’t necessarily need to use plugin.

If your post images are hosted from another server or image hosting sites and your theme only shows thumbs from image you upload to your own server, here’s the solution:

Open functions.php and paste the following code:

//Thumbnail on homepage
function catch_first_image() {
 global $post, $posts;
 $first_img = '';
 ob_start();
 ob_end_clean();
 $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
 $first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
 $first_img = "/images/default.jpg";
 }
 return $first_img;
}

Save it and then open index.php and paste the following code:

<div  align="center">
<img src="<?php echo catch_first_image() ?>" width="420px" height="180px" title="<?php the_title(); ?>" >
</div>

You can Replace:

“center” –> “left” or “right”

width and height –> to your desired sizes

FOR THUMBS WITH LINK:

<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"> <img src="<?php echo catch_first_image() ?>" width="420px" height="180px" title="<?php the_title(); ?>" ></a>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s