DedeCMS有很多標(biāo)簽調(diào)用時自帶了HTML代碼,其實(shí)留給自己處理更好更靈活。比如自定義字段為圖片時(字段名:name),輸出的格式有時候并不是我們想要的,內(nèi)容頁用{dede:field.name/}
{dede:img text='' width='270' height='129'}/uploads/101017/1-10101H21F54P.gif{/dede:img}
前臺輸出格式如下:
<li> <a href='/uploads/140420/1-140420164Z2914.jpg' target='_blank'> <img src='/uploads/140420/1-140420164Z2914.jpg' width='253' border='0'/> </a> </li>
創(chuàng)建自定義函數(shù)
打開/include/extend.func. php,在最下面復(fù)制以下代碼(?>前面)
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; } }
前臺內(nèi)容頁格式為:
<img alt="{dede:field.title/}" src="{dede:field.name function='GetOneImgUrl(@me,1)'/}"> @me,0 代表只輸出路徑 @me,1 代表連寬、高一起輸出
同樣的列表頁或首頁用相應(yīng)的標(biāo)簽套進(jìn)去就行了。