Create Thumbnails WordPress From First In Post Or Page
This article related to the avatar for post and page, if anyone know how to registered and referred thumbnail, can be found here.
A while ago I did a project Get post to 200 sites from a site that provides information and my initial 200 sites that store images when Get in the process of implementation of this project has many shortcomings, photos get sometimes error prone, then I redirect to another plan is not to save the image on where to obtain images from the web site and provide information, the first image in the post thumbnail.
The real you is very simple, all this code I’ve built, you just follow the instructions to put that line of code in your theme it.
First you copy my code and paste it into your functions.php file
<?php
function getImage($num)
{
global $more;
$more = 1;
$content = get_the_content();
$count = substr_count($content, '<img');
$start = 0;
for($i=1;$i<=$count;$i++) {
$imgBeg = strpos($content, '<img', $start);
$post = substr($content, $imgBeg);
$imgEnd = strpos($post, '>');
$postOutput = substr($post, 0, $imgEnd+1);
$image[$i] = $postOutput;
$start=$imgEnd+1;
$cleanF = strpos($image[$num],'src="')+5;
$cleanB = strpos($image[$num],'"',$cleanF)-$cleanF;
$imgThumb = substr($image[$num],$cleanF,$cleanB);
}
if(stristr($image[$num],'<img')) { echo $imgThumb; }
$more = 0;
}
?>
Then you download the file timthumb.php on leave on the theme you are using offline folders, file work cut image from a given image.
You can download from this link or direct you used always to address this file replaces the address in the code I am using offline:
http://timthumb.googlecode.com/svn/trunk/timthumb.php
Then you place this code where you want to display thumbnail, usually in the file as: single.php, category.php, archire.php, page
<div>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php getImage('1'); ?>&w=150&h=150&zc=1">
</a>
</div>
if you use this file directly on google, the above code will become like this
<div>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<img src="http://timthumb.googlecode.com/svn/trunk/timthumb.php?src=<?php getImage('1'); ?>&w=150&h=150&zc=1">
</a>
</div>
Have you done it yet?
Wish you success.
Mình cũng rất thích dùng code hơn là plusin.
Lạm dụng plusin khiến tốc độ load của site tăng lên đáng kể
Thanks Mình đang tìm cái này