zblog php获取文章的第一张图片,没有调用默认图片

2024-2-26 / 0 评论 / 20 阅读

php版的zblog提供了获取文章首张图片的函数代码,直接把函数代码添加到模板文件中,然后调用对应的变量输入图片url即可,默认用于最新文章列表,通过代码调整可用于分类文章列表,比如zblog php企业模板的首页产品展示列表。

下面代码一般放入include.php中

复制代码function slimgs($src){global $zbp;if(!$zbp->CheckPlugin('IMAGE')){$thumbs_src=$src;}else{$thumbs_src=IMAGE::getPicUrlBy($src,4);}return $thumbs_src;}function slimg($as,$pos){global $zbp;$temp=mt_rand(1,3);$pattern = "/<img.*?src=(\"|')?(?<src>.*?\.(gif|jpg|jpeg|png))(\"|')?.*?>/";   $content = $as->Content;if($pos->Metas->thumbnail){$temp=$pos->Metas->thumbnail;}else{if(preg_match($pattern,$content,$matchContent) && isset($matchContent['src'])){$temp=$matchContent['src'];}else{$temp=$zbp->host . "zb_users/theme/" .$zbp->theme. "/style/images/pic.png";}}$src = slimgs($temp);return $src;}

调用代码(在循环里面调用):

复制代码{slimg($related,$related)}

 

×

如果觉得文章对您有用,请随意打赏。
您的支持是我们继续创作的动力!

微信打赏

微信扫一扫

支付宝打赏

支付宝扫一扫

扫描二维码,在手机上阅读

评论一下?

OωO
取消