Zblog教程

zblogphp文章缩略图调用方法汇总

Zblog教程 51源码 2023-05-08 人阅读

前年的时候写过一篇“zblogphp调用文章缩略图的方法”,然后被吐槽方法不管用...

本文就来汇总一下最新的zblogphp调用文章缩略图的所有方法。

直接原生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}
$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。

這几个插件都有自己的侧重点,大家可以根据自己的需求选择合适的插件。

版权声明:文章搜集于网络,如有侵权请联系本站,转载请说明出处:https://www.51yma.cn/jiaocheng/Zblogjiaocheng/1214.html
文章来源:-https://www.txcstx.com/post/984.html