您的位置:首页 > 其它

自定义字段 图片(无格式)只调用图片路径

2014-04-19 19:49 288 查看
1、修改 /include/extend.func加入以下代码

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;
}
}


[field:自定义图片字段名 function="GetOneImgUrl(@me,显示类型)"/]

比如:我们的自定义图片字段名为 datu 和 xiaotu,

只举例调用datu字段的方法,那么调用方式有以下两种:

[field:datu function='GetOneImgUrl(@me,0)'/] 调用图片的信息,自动调用宽度和高度(已包含Html代码的<img />)

[field:datu function='GetOneImgUrl(@me,1)'/] 只调用图片地址,一般可用于背景图嵌套
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: