前些天写过一个thpecho的文章缩略图插件。https://mrasong.com/a/thumbnail-for-typecho 如果没有图片的时候将会出现一张空白图,这样对于网站访客是相当不友好的,
现在改了下,通过插入<!--showThumbnail-->来显示缩略图,默认不显示。
默认只从附件中读取,若想通过附件>缩略图>分类图片>随机图片的方式
在Plugin.php文件中找到以下代码,将其去注释。
/**↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓* preg_match_all( "/\<img.*?src\=(\'|\")(.*?)(\'|\")[^>]*>/i", $content, $matches ); $imgCount = count($matches[0]); if( $imgCount >=1 ){ $img = $matches[2][0]; }else { if( file_exists( $_SERVER['DOCUMENT_ROOT'] . $dir_cate . $cate . $default_ext ) ){ $img = $dir_cate . $cate . $default_ext ; }else{ $img = Thumbnail_Plugin::randPic( $dir_rand, $default_img, $arr_ext ); //随机图片 } } *↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑**/
若只想通过文章中匹配,请将上面代码改为:
preg_match_all( "/\<img.*?src\=(\'|\")(.*?)(\'|\")[^>]*>/i", $content, $matches ); $imgCount = count($matches[0]); if( $imgCount >=1 ){ $img = $matches[2][0]; }
修改后的插件下载
下一步找时间我会将此插件完善,可以在插件设置中自己配置