资讯中心
News
zblogphp文章缩略图调用方法汇总
发布时间:2019-01-22 13:16   您所在的位置: 网站首页 > 新闻资讯 > 建站知识

下面为大家分享一下最新的zblogphp调用文章缩略图的所有方法,希望对大家制作zblogphp模板有所帮助。

直接原生php代码调用:

天兴工作室自己使用的代码,直接上代码:

PHP
{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
{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://www.jianzhan0.com/zhishi/49280.html