zblogphp主题制作cms等图片调用代码
zblogphp主题制作cms等图片调用代码,其实这个代码早就有人发布在网上了。老手多知道,新人不一定就知道用这个调用了,可能还是用老云之前发布的zblogphp文章缩略图调用方法那种调用方法,之前的代码在制作cms类主题的时候可能就不好用了。个人感觉用这个功能强大,通用。
在主题目录下include.php里插入以下函数。
function Yun_blog_Thumbs($src,$width,$height) { global $zbp; if (!$zbp->CheckPlugin('IMAGE')) { $thumbs_src=$src; } else { $thumbs_src=IMAGE::getPicUrlBy($src,$width,$height,4); } return $thumbs_src; } function Yun_blog_FirstIMG($as,$width,$height) { global $zbp; $temp=mt_rand(1,3); $pattern = "/<img.*?src=(\"|')?(?<src>.*?\.(gif|jpg|jpeg|png))(\"|')?.*?>/"; $content = $as->Content; if(preg_match($pattern,$content,$matchContent) && isset($matchContent['src'])){ $temp=$matchContent['src']; } else { $temp=$zbp->host . "zb_users/theme/" .$zbp->theme. "/images/pic.png"; } $src = Yun_blog_Thumbs($temp,$width,$height); return $src; }
其中Yun_blog为主题ID。
调用的代码:放在你想展示图片的模板地方,
{Yun_blog_FirstIMG($article,200,150)}
例如循环代码中调用的变量是$related.
{{foreach Getlist($mknum,$mkid,null,null,null,null,array('has_subcate'=>true)) as $related } <li> <a href="{$related.Url}" class="clear"> <div class="list-img"><img src="{xianbao_FirstIMG($related,200,150)}"></div> <span>{$related.Title}</span> </a> </li> {{/if}
你就要吧$article改成$related,其中200,150分别为宽度高度可以自行修改。
本文链接:https://www.yunblog.net/post/234.html
版权声明:站内所有文章皆来自网络转载,只供主题演示使用,并无任何其它意义!