Typecho 自定义文章缩略图显示

前些天写过一个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];
            }


修改后的插件下载

Thumbnail-show.zip

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


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

添加新评论