(5.7sp1版测试通过)织梦DedeCMS网站内容模型普通文章调用自定义图片字段的方法:
方法一:我们首先需要创建一个自定义函数,
找到:/include/extend.func.php ,在< ?php 后加入以下代码:
01 |
function GetOneImgUrl($img,$ftype=1){ |
03 |
$dtp = new DedeTagParse(); |
04 |
$dtp->LoadSource($img); |
05 |
if(is_array($dtp->CTags)){ |
06 |
foreach($dtp->CTags as $ctag){ |
07 |
if($ctag->GetName()=='img'){ |
08 |
$width = $ctag->GetAtt('width'); |
09 |
$height = $ctag->GetAtt('height'); |
10 |
$imgurl = trim($ctag->GetInnerText()); |
17 |
$img .= '<img src="'.$imgurl.'" width="'.$width.'" height="'.$height.'" />'; |
|
保存就可
调用实例:
1 |
{dede:arclist addfields='pro_img1,pro_img2' channelid='1' } |
2 |
<img src="[field:pro_img1 function='GetOneImgUrl(@me,1)'/]" width="100"height="100" /> |
3 |
<a href="[field:pro_img2 function='GetOneImgUrl(@me,1)'/]"><img src="[field:pro_img2function='GetOneImgUrl(@me,1)'/]" width="100" height="100" /></a> |
|
channelid='1'说明一下是频道前面的id数字
'pro_img1,pro_img2' 这些是图片字段替换成你的就可
方法二:
利用正则表达式来
1 |
{dede:arclist addfields='pro_img1' channelid='1' } |
2 |
<img src="[field:pro_img1 runphp='yes'] |
3 |
$ndtp = new DedeTagParse(); |
4 |
$ndtp->LoadSource(@me); |
5 |
$ntag = $ndtp->GetTag("img"); |
6 |
@me = trim($ntag->GetInnerText()); |
7 |
[/field:pro_img1]" width="100" height="100" /> |
|
缺点只能保存一个 优点不用去改动源核心文件
channelid和typeid区别
channelid 频道调用 是在内容模型里管理,频道名称的前面也有一个id,这个ID用 channelid调用。

这个调用需要频道里面有子栏目才可以的。
而typeid 就是纯粹的栏目调用 可以调用里面的文章

这个就是 channelid频道和typeid栏目标签调用的区别。