(5.7sp1版測試通過)織夢DedeCMS網站內容模型普通文章調用自定義圖片字段的方法:
方法一:我們首先需要創建一個自定義函數,
找到:/include/extend.func.php ,在< ?php 后加入以下代碼:
| function GetOneImgUrl($img,$ftype=1){if($img <> ''){$dtp = new DedeTagParse();$dtp->LoadSource($img);if(is_array($dtp->CTags)){foreach($dtp->CTags as $ctag){if($ctag->GetName()=='img'){$width = $ctag->GetAtt('width');$height = $ctag->GetAtt('height');$imgurl = trim($ctag->GetInnerText());$img = '';if($imgurl != ''){if($ftype==1){$img .= $imgurl;}else{$img .= '<img src="'.$imgurl.'" width="'.$width.'" height="'.$height.'" />';}}}}}$dtp->Clear();return $img;}} | 
保存就可
	 
調用實例:
| {dede:arclist  addfields='pro_img1,pro_img2' channelid='1' }<img src="[field:pro_img1 function='GetOneImgUrl(@me,1)'/]" width="100" height="100"  /><a href="[field:pro_img2 function='GetOneImgUrl(@me,1)'/]"><img src="[field:pro_img2function='GetOneImgUrl(@me,1)'/]" width="100" height="100"  /></a>{/dede:arclist} | 
channelid='1'說明一下是頻道前面的id數字
'pro_img1,pro_img2' 這些是圖片字段替換成你的就可
	 
方法二:
利用正則表達式來
| {dede:arclist  addfields='pro_img1' channelid='1' } <img src="[field:pro_img1 runphp='yes']                      $ndtp = new DedeTagParse();                      $ndtp->LoadSource(@me);                      $ntag = $ndtp->GetTag("img");                     @me = trim($ntag->GetInnerText());            [/field:pro_img1]" width="100" height="100"  />{/dede:arclist} | 
缺點只能保存一個 優點不用去改動源核心文件
channelid和typeid區別
	channelid 
	
	這個調用需要頻道里面有子欄目才可以的。
	而typeid 
	
	
這個就是 channelid頻道和typeid欄目標簽調用的區別。
新聞熱點
疑難解答