在dedecms文章页中我们经常会显示相关文章之类的文章列表,就需要使用{dede:likearticle}标签,但是默认的likearticle是不能显示自定义的附加字段的。
- 第一种解决方法
打开 /include/extend.func.php ,在最下面新建一行,插入
if(!function_exists('GetAddField')){function GetAddField($aid,$addField){global $dsql;$row = $dsql->GetOne("SELECT c.addtable FROM dede_archives AS a LEFT JOIN dede_channeltype AS c ON a.channel=c.id where a.id='$aid'");$addtable = trim($row['addtable']);$row = $dsql->GetOne("SELECT $addField FROM `$addtable` WHERE aid=$aid");return $row["$addField"];}}
如图所示
模板中dede:likearticle调用自定义字段标签写法
{dede:likearticle row='10' col='' titlelen='100' infolen='200'}<a href="[field:arcurl/]">[field:title/]</a><p>价格:¥[field:id function=GetAddField(@me,'jiage')/]</p>{/dede:likearticle}
- 第二种解决办法
打开 include/taglib/likearticle.lib.php 找到
if($keyword != '')
在它的上面加入
//获得附加表的相关信息$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;}}}}}
继续搜索
tp.sitepath
改成
tp.sitepath $addField
有2处,都要修改,然后继续搜索
arc.typeid=tp.id
改成
arc.typeid=tp.id $addJoin
有2处,都要需改
模板中dede:likearticle调用自定义字段标签写法
{dede:likearticle row='10' col='' titlelen='100' infolen='200'}<a href="[field:arcurl/]">[field:title/]</a><p>价格:¥[field:jiage/]</p>{/dede:likearticle}