首先,在内容页或列表页中,Dedecms默认输出的图片格式如下: 这种格式显然不够灵活,尤其是在需要自定义图片展示效果时。为了实现更灵活的图片调用,我们需要对Dedecms进行一些调整。
在设置自定义字段为图片时,务必选择“图片(仅网址)”选项。这样,输出的格式会简化为以下形式:
{dede:imgtext='' width='270' height='129'}/uploads/101017/1-10101H21F54P.gif{/dede:img}
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 .= '
';
}
}
}
}
}
$dtp->Clear();
return $img;
}
}
最后,在列表页或首页中,只需将相应的标签嵌套进去即可实现同样的效果。通过以上步骤,您可以轻松实现Dedecms自定义图片字段的灵活调用,满足更多个性化需求。