DedeCMS系统自定义字段图片调用问题的解决方法
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'><strong>一、实现方法1)创建自定义函数</strong><br><br>
打开 /include/extend.func.php 文件(注:这个文件就是系统预留的自定义函数接口文件,主要用于二次开发用的。如果你是老版本,默认没有这个文件,自己创建一个PHP文件即可),在最下面的?>上一行加入以下函数代码:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div class="right">
<span><u>复制代码</u></span>
</div>
代码如下:</div>
<div class="msgborder" id="phpcode1" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
/****************<br>
function GetOneImgUrl<br>
@@ 功能:读取自定义字段<u>图片</u>地址<br>
*****************/<br>
function GetOneImgUrl($img,$ftype=1){<br>
if($img <> ''){<br>
$dtp = new DedeTagParse();<br>
$dtp->LoadSource($img);<br>
if(is_array($dtp->CTags)){<br>
foreach($dtp->CTags as $ctag){<br>
if($ctag->GetName()=='img'){<br>
$width = $ctag->GetAtt(‘width');<br>
$height = $ctag->GetAtt(‘height');<br>
$imgurl = trim($ctag->GetInnerText());<br>
$img = '';<br>
if($imgurl != ''){<br>
if($ftype==1){<br>
$img .= $imgurl;<br>
}<br>
else{<br>
$img .= ‘<img src=''‘.$imgurl.''' width=''‘.$width.''' height=''‘.$height.''' />';<br>
}<br>
}<br>
}<br>
}<br>
}<br>
$dtp->Clear();<br>
return $img;<br>
}<br>
}</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
保存后关闭即可。<br>
2)函数调用方法 问:我们创建好函数以后,那么这个函数要如何来调用呢?<br>
答:本函数的调用方法为:<br>
<br>
比如:我们的自定义图片字段名为 imgurl ,那么调用方式有以下两种:<br>
<!–调用图片的信息,自动调用宽度和高度(已包含Html代码的<img />标签)–><br>
<!–只调用图片地址,一般可用于背景图嵌套–></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
<strong>二、示例演示</strong><br><br>
1)模型字段添加 进入网站后台,点击[核心]——[内容模型管理],点击“普通文章''的“更改''按钮,进入编辑界面,切换到“字段管理''选项,点击“添加新字段''。<br>
创建好字段以后,我们在增加或编辑文档时候,那么就会有这个字段了。<br>
上传好你要显示的图片以后,保存即可。<br>
2)前台调用 原本我们前台调用这个字段的方法,就是通过arclist标签的 channelid 与 addfields 两个参数来配合调用,这里不再重复的一一熬述。但大体的自定义字段的方法是这样的:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
{dede:arclist row='2′ channeld='1′ addfields='自定义字段1,自定义字段2′}<br>
底层模板 insertext<br>
{/dede:arclist}</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
运用到我们刚才的这个函数,调用方法为:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
{dede:arclist row='5′ orderby='id' channelid='1′ addfields='imgurl'}<br>
<li></li><br>
{/dede:arclist}</p>
頁:
[1]