在dedecms文章页中我们经常会显示相关文章之类的文章列表,就需要使用{dede:likearticle}标签,但是默认的likearticle是不能显示自定义的附加字段的。
解决办法打开 include/taglib/likearticle.lib.php 找到1if($keyword != '')在它的上面加入01//获得附加表的相关信息02$addField = "";03$addJoin = "";04if(is_object($refObj->ChannelUnit))05{06 $addtable = $refObj->ChannelUnit->ChannelInfos['addtable'];07 if($addtable!="")08 {09 $addJoin = " LEFT JOIN $addtable ON arc.id = ".$addtable.".aid ";10 $addField = "";11 $fields = explode(",",$refObj->ChannelUnit->ChannelInfos['listfields']);12 foreach($fields as $k=>$v)13 {14 $nfields[$v] = $k;15 }16 foreach($refObj->ChannelUnit->ChannelFields as $k=>$arr)17 {18 if(isset($nfields[$k]))19 {20 if(!empty($arr['rename']))21 {22 $addField .= ",".$addtable.".".$k." as ".$arr['rename'];23 }24 else25 {26 $addField .= ",".$addtable.".".$k;27 }28 }29 }30 }31}
继续搜索1tp.sitepath改成1tp.sitepath $addField有2处,都要修改,然后继续搜索1arc.typeid=tp.id改成1arc.typeid=tp.id $addJoin有2处,都要需改模板中dede:likearticle调用自定义字段标签写法1{dede:likearticle row='10' col='' titlelen='100' infolen='200'}2<a href="[field:arcurl/]">[field:title/]</a>3<p>价格:¥[field:jiage/]</p>4{/dede:likearticle}