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

作者:liaoren 时间:19-03-01 阅读数:19769人阅读

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)}



发表评论

请先登录 再评论,若不是会员请先注册