您的位置:首页 > 其它

织梦5.6 5.7(DedeCMS)自定义图片类型字段的调用

2017-02-09 21:16 489 查看
织梦自定义字段如果设置为图片类型,那么数据库写入进去的数据变成下面这种形式的内容:

{dede:img text='' width='270' height='129'} /uploads/117517/1-11751H21F54P.png {/dede:img}

很明显,这样不方便前台调用,这是织梦自定义图片字段的处理方式(/include/customfields.func.php)造成的,要解决这个问题,我们要创建一个自定义函数,实现方式是:

打开 /include/extend.func.php 文件,在里面加入以下函数代码:

/****************
function GetOneImgUrl
@@ 功能:读取自定义字段图片地址
@@ 时间:2010-10-17 22:48
*****************/

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,显示类型)"/]

例如:自定义图片字段名为 nextimg ,其调用方式有如下两种:
第一:只调用图片路径

[field:nextimg function='GetOneImgUrl(@me,1)'/]

第二:调用整个img标签

[field:nextimg function='GetOneImgUrl(@me,0)'/]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐