前年的时候写过一篇“zblogphp调用文章缩略图的方法”,然后被吐槽方法不管用...
本文就来汇总一下最新的zblogphp调用文章缩略图的所有方法。
天兴工作室自己使用的代码,直接上代码:
{php} $temp=mt_rand(1,1); $pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png]))[\'|\"].*?[\/]?>/"; $content = $article->Content; preg_match_all($pattern,$content,$matchContent); if(isset($matchContent[1][0])) $temp=$matchContent[1][0]; else $temp=$zbp->host."zb_users/theme/$theme/include/pic.png"; {/php} <img src="{$temp}">
注意:要保证你正在使用的主题的“include”文件夹里面有一张“pic.png”的图片,這个图片就是在你的文章内没有图片的时候显示的默认缩略图片。
zblog官方的代码:
{php} $temp=mt_rand(1,4); $pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png]))[\'|\"].*?[\/]?>/"; $content = $article->Content; preg_match_all($pattern,$content,$matchContent); if(isset($matchContent[1][0])) $temp=$matchContent[1][0]; else $temp=$zbp->host."zb_users/theme/$theme/style/images/random/$temp.jpg"; //需要在相应位置放置4张jpg的文件,名称为1,2,3,4 {/php} <img src="{$temp}" />
zblogphp调用文章缩略图的插件已经有很多了,大多数都是免费的,那么天兴工作室就为大家推荐几个缩略图调用插件:
IMAGE:https://app.zblogcn.com/?id=1000;
手动裁剪缩略图:https://app.zblogcn.com/?id=565;
sf_img1:https://app.zblogcn.com/?id=511;
FirstIMG:https://app.zblogcn.com/?id=387。
這几个插件都有自己的侧重点,大家可以根据自己的需求选择合适的插件。
本文地址:http://2015.imtx.wang/post/984.html
版权说明:如非注明,本站文章均为 天兴工作室 原创,转载请注明出处和附带本文链接。
测试的
天兴工作室
天兴工作室
天兴工作室
天兴工作室
天兴工作室
天兴工作室
天兴工作室