消失的那么快
纪念我的放肆
当前位置:首页 > .html

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

作者:ling发布时间:2023-04-03 14:59分类: 网页设计 浏览:20评论:0


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

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



发表评论: