码库记事本

码库记事本

织梦likearticle相关文档标签调用附加自定义字段

小诸哥 0

在dedecms文章页中我们经常会显示相关文章之类的文章列表,就需要使用{dede:likearticle}标签,但是默认的likearticle是不能显示自定义的附加字段的。

解决办法打开 include/taglib/likearticle.lib.php 找到:

<span style="font-size:14px;">if($keyword != '')</span>

在它的上面加入:

<span style="font-size:14px;">

//获得附加表的相关信息

$addField = "";

$addJoin = "";

if(is_object($refObj->ChannelUnit)){

$addtable = $refObj->ChannelUnit->ChannelInfos['addtable'];

if($addtable!=""){

$addJoin = " LEFT JOIN $addtable ON arc.id = ".$addtable.".aid ";

$addField = "";

$fields = explode(",",$refObj->ChannelUnit->ChannelInfos['listfields']);

foreach($fields as $k=>$v){

$nfields[$v] = $k;

}

foreach($refObj->ChannelUnit->ChannelFields as $k=>$arr){

if(isset($nfields[$k])){

if(!empty($arr['rename'])){

$addField .= ",".$addtable.".".$k." as ".$arr['rename'];

}else{

$addField .= ",".$addtable.".".$k;

}

}

}

}

}

</span>

继续搜索:

<span style="font-size:14px;">1tp.sitepath</span>

改成:

<span style="font-size:14px;">1tp.sitepath $addField</span>

有2处,都要修改,然后继续搜索:

<span style="font-size:14px;">1arc.typeid=tp.id</span>

改成:

<span style="font-size:14px;">1arc.typeid=tp.id $addJoin</span>

有2处,都要需改模板中dede:likearticle调用自定义字段标签写法:

<span style="font-size:14px;">

{dede:likearticle row='10' col='' titlelen='100' infolen='200'}

<a href="[field:arcurl/]">[field:title/]</a>

<p>价格:¥[field:jiage/]</p>

{/dede:likearticle}

</span>

标签: 织梦 likearticle