精華 帝國PHP系統列表頁,如何調用內容頁的多張圖片?
帝國列表調用多張圖片的操作方法:
第一步:確保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="http://www.viagraonlinego.com/662.html'.$myimg[0].'" /></div><a href="http://www.viagraonlinego.com/[!--titleurl--]" title="[!--oldtitle--]" target="_blank">[!--title--]</a></li> ?';
說明:
$myimg=getImgs($r[newstext]);
這里$myimg就是所有圖片的地址數組。
count($myimg) 就是圖片個數,可以放到需要調用的地方。