最近用dedecms做了一个“中介”自定义模型,添加了一个“中介相片”的数据类型图片,上传图片后,数据库里显示为:{dede:img text=’’ width=‘256’ height=‘256’} /uploads/allimg/200122/1-2001221U92LH.png {/dede:img},内容页的src调取的不是/uploads/allimg/200122/1-2001221U92LH.png,而是全部代码,导致内容页无法显示该图片。
如何让内容页显示自定义模型的数据类型图片呢?
解决方案:
1、在include/extend.func.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;
}
}
2、将templets/system/channel_article_image.htm所有代码改为一个很简单的代码[field:imgsrc/]。
3、内容页模板调用{dede:field.自定义图片字段名/},如{dede:field.zhongjiepic/},内容页显示图片成功。