在网站建设中,Dedecms 是一款功能强大的内容管理系统。熟悉其标签功能,可以让我们在前台灵活调用后台数据。如果能对这些标签进行优化改进,将使系统更加完善。


最近,我在扩展和细分自己网站的栏目时,遇到了一个需求:希望某个特定栏目不显示在首页的最新文章列表中。按照 Dedecms 的传统方法,可以通过在 arclist 标签的 typeid 属性中指定需要显示的栏目ID来实现。然而,当栏目数量较多时,这种方法不仅繁琐,而且后期维护成本较高。


为了解决这个问题,我尝试通过修改代码来支持 notypeid 属性,从而排除不需要显示的栏目。以下是具体的操作步骤:


首先,打开 /include/taglib/arclist.lib.php 文件,找到以下代码段(大约在第130行):


return lib_arclistDone(
         $refObj, $ctag, $typeid, $ctag->GetAtt('row'), $ctag->GetAtt('col'), $titlelen, $infolen,
         $ctag->GetAtt('imgwidth'), $ctag->GetAtt('imgheight'), $listtype, $orderby,
         $ctag->GetAtt('keyword'), $innertext, $envs['aid'], $ctag->GetAtt('idlist'), $channelid,
         $ctag->GetAtt('limit'), $flag,$ctag->GetAtt('orderway'), $ctag->GetAtt('subday'), $ctag->GetAtt('noflag'),
         $tagid,$pagesize,$isweight
     );


在最后括号内添加如下内容(注意前面的逗号):


,$ctag->GetAtt('notypeid')


接下来,继续查找代码段(大约在第168行):


function lib_arclistDone(&$refObj, &$ctag, $typeid=0, $row=10, $col=1, $titlelen=30, $infolen=160,
        $imgwidth=120, $imgheight=90, $listtype='all', $orderby='default', $keyword='',
        $innertext='', $arcid=0, $idlist='', $channelid=0, $limit='', $att='', $order='desc', $subday=0, $noflag='',$tagid='', $pagesize=0, $isweight='N')


同样,在括号最后添加以下内容:


,$notypeid=0


最后,定位到以下代码:


$orwheres[] = ' arc.arcrank > -1 ';


在其前插入以下代码:


if(!empty($notypeid))
{
    $orwheres[] = " and arc.typeid NOT IN (".GetSonIds($notypeid).")";
}


完成以上修改后保存文件,并测试 arclist 标签中的 notypeid 属性是否生效。例如:


{dede:arclist row=6 orderby=pubdate type='image.' imgwidth='108' imgheight='150' channelid='1' notypeid='9'}


此方法对于拥有复杂栏目结构的网站非常实用。通过新增 notypeid 属性,可以更方便地控制某些栏目的显示与隐藏,提高开发效率的同时也降低了维护难度。