详情页

帝国cms列表页调用多个内容页图片

时间:2023年11月10日

编辑:佚名

帝国cms列表页调用多个内容页图片的操作方法:
第一步:
假定你是新闻模型,假定你的newstext字段在主表中,假定你已经在系统模型中勾选--- newstext字段的列表显示,已确保newstext字段可以在列表页list.var中调用。
第二步:
复制以下函数到e/class/userfun.php 中
function getImgs($content,$order='ALL'){
$content=stripslashes($content);
$pattern="/<img\b.*?\bsrc=([\'|\"])(.*?)\\1.*?[\/]?>/i";
$i=2;
preg_match_all($pattern,$content,$match);
if(isset($match[$i])&&!empty($match[$i])){
if($order==='ALL'){
return $match[$i];
}
if(is_numeric($order)&&isset($match[$i][$order])){
return $match[$i][$order];
}
}
return '';
}
第三步:列表模版勾选,使用程序代码,列表内容模板(list.var) (*)内容可参考:
$myimg=getImgs($r[newstext]);
$listtemp='  <li> <DIV class="thumbImage" ><img src="'.$myimg[0].'" /></div><a href="[!--titleurl--]" title="[!--oldtitle--]" target="_blank">[!--title--]</a></li>  ';
说明:
$myimg=getImgs($r[newstext]);
这里$myimg就是所有图片的地址数组。
count($myimg) 就是图片个数,遍历你总会吧?
相关文章
猜你需要