帝国cms列表页调用文章内容页多个图片方法

MoBan5源码 | 2023-12-13 10:15:04 |
帝国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) 就是图片个数,可以放到需要调用的地方。

好了,以上就是帝国cms列表页调用文章内容页多个图片方法希望对大家有所帮助。

 


标签: