WordPress no plugin automatically displays thumbnails

Like toss to modify the wordpress theme friends, certainly encountered such a problem, would like to show thumbnails in the home page, there are plug-ins can be achieved, but not easy to operate and control, after all, the code is written, and today to share with you, No plug-in, pure code is how to achieve the first page of the article thumbnails, the method is very simple, even if you do not understand the code, according to the steps can also be. Of course, the thumbnail is selected in the article in the first picture, if the article does not contain pictures, show the default picture, so you have to set a default picture location.
Into the topic, start to add the first page thumbnail, simple 3 steps can be achieved:

The first step: find the use of the theme template function.php file in the <? Php and?> Add the following code:
function thumb_img ($ soContent) {
$ soImages = ‘~ <img [^ \>] * \ /> ~’;
preg_match_all ($ soImages, $ soContent, $ thePics);
$ allPics = count ($ thePics [0]);
if ($ allPics> 0) {
echo “<span id = ‘thumb’>”;
echo $ thePics [0] [0];
echo ‘</ span>’;
else {
echo “<span id = ‘thumb’>”;
echo “<img src = ‘”;
echo bloginfo (‘template_url’);
echo “/images/thumb.gif ‘> </ span>”;
This is a method of displaying thumbnails, automatically retrieving the first picture of the article, and if you do not show the current theme /images/thumb.gif so you should have this thumb.gif picture ready.

The second step: find the index.php file that is the first page file, find the_content (); or similar code before it add the following code:
thumb_img ($ post-> post_content);
This call the method just now, in fact, the thumbnail has been completed. But you see the effect must be very unexpected, the size of the picture should be no control, will be ugly.

Step 3: Add thumbnail style CSS code:
This is the cloud station used in the thumbnail style, you can make do with the use, and then modify it
#thumb {margin: 5px 15px 5px 5px; width: 145px; height: 120px; border: 3px solid #eee; float: left; overflow: hidden;}
#thumb img {max-height: 186px; max-width: 186px}

Well, so there is a thumbnail showing a kind of show it.