各位编程爱好者,你是否曾在织梦DedeCMS模板中遇到需要自定义模型数据类型图片调用的难题?今天,我们就来聊聊这个话题,让你轻松掌握如何在DedeCMS中调用自定义图片字段的方法。
方法一:创建自定义函数
首先,我们需要在/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 .= '';
}
}
}
}
}
}
$dtp->Clear();
return $img;
}
保存后,你就可以在模板中调用这个函数了。
调用实例
{dede:arclist addfields='pro_img1,pro_img2' channelid='1' }
