帝国cms列表页如何调用多张内容页图片
注意事项:
1、本方法是用于列表页list.var循环部分,不能用于灵动标签调用的文章列表循环中。
2、调用内容页正文字段newstext中的图片,需要先把字段newstext改成主表(默认是副表),之后在系统模型中勾选newstext字段的列表显示。
帝国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='<img src=\"'.$myimg[0].'\" /><img src=\"'.$myimg[1].'\" /><img src=\"'.$myimg[3].'\" /><a href=\"'.$r[titleurl].'\" >'.$r[title].'</a>';
说明:
$myimg=getImgs($r[newstext]);这里$myimg就是所有图片的地址数组。
count($myimg) 就是图片个数,遍历你总会吧?