前些天写过一个 thpecho 的文章缩略图插件。https://mrasong.com/a/thumbnail-for-typecho 如果没有图片的时候将会出现一张空白图,这样对于网站访客是相当不友好的, 现在改了下,通过插入<!--showThumbnail-->来显示缩略图,默认不显示。 默认只从附件中读取,若想通过附件>缩略图>分类图片>随机图片的方式 在 Plugin.php 文件中找到以下代码,将其去注释。

 1preg_match_all( "/\<img.*?src\=(\'|\")(.*?)(\'|\")[^>]*>/i", $content, $matches );
 2$imgCount = count($matches[0]);
 3if( $imgCount >=1 ){
 4        $img = $matches[2][0];
 5}else {
 6
 7    if( file_exists( $_SERVER['DOCUMENT_ROOT'] . $dir_cate . $cate . $default_ext ) ){
 8        $img = $dir_cate . $cate . $default_ext ;
 9    }else{
10        $img = Thumbnail_Plugin::randPic( $dir_rand, $default_img, $arr_ext );  //随机图片
11    }
12}

若只想通过文章中匹配,请将上面代码改为:

1preg_match_all( "/\<img.*?src\=(\'|\")(.*?)(\'|\")[^>]*>/i", $content, $matches );
2$imgCount = count($matches[0]);
3if( $imgCount >=1 ){
4        $img = $matches[2][0];
5}

修改后的插件下载

Thumbnail-show.zip

下一步找时间我会将此插件完善,可以在插件设置中自己配置

您可以通过:
http://list.qq.com/cgi-bin/qf_invite?id=6c9a0782cf76d49165cdc525b5e8b42ac211ffa6886a3de5
来订阅此博客,每天发送博客更新到您的邮箱。