帝国列表调用多张图片的操作方法:
第一步:确保newstext字段可以在列表页list.var中调用
假定你是新闻模型,假定你的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) 就是图片个数,可以放到需要调用的地方。
本文摘自网络,不代表短经典网立场 https://www.duanjingdian.com/662.html