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

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


转载请说明出处内容投诉
zblog资源网 » zblog php获取文章的第一张图片,没有调用默认图片

发表评论

欢迎 访客 发表评论

加入会员,享受更优质的zblog技术服务!

马上加入 会员说明 联系客服