Dedecms 是一款功能强大的内容管理系统,其模板引擎标签功能尤为突出。掌握这些标签后,我们可以在前台灵活调用各种形式的内容数据。然而,如果我们对 Dedecms 的默认标签进行改进,就能实现更多自定义功能。本文将详细介绍如何为 Dedecms 的 arclist 标签添加 notypeid 属性。

当我们扩展和细分栏目时,可能会遇到一些问题。例如,我们希望某个栏目的内容不在首页的最新文章列表中显示。按照 Dedecms 的现有方法,需要在 arclist 标签的 typeid 属性中手动设置所有需要显示的栏目 ID。但如果栏目 ID 过多,维护起来会非常麻烦。因此,我们可以尝试为 arclist 标签添加 notypeid 属性,以排除特定栏目。

以下是具体操作步骤:

第一步:修改 arclist.lib.php 文件

找到并打开 /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')
    

第二步:修改 lib_arclistDone 函数

接着,找到以下代码段:


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 ';
    

添加以下代码以实现 notypeid 功能:


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

保存并测试

完成以上修改后,保存文件并在模板中使用 arclist 标签时添加 notypeid 属性。例如:


{dede:arclist row=6 orderby=pubdate type='image.' channelid='1' notypeid='9'}
{/dede:arclist}
    

通过这种方式,您可以轻松排除特定栏目中的内容,使网站管理更加高效。

总结来说,通过对 Dedecms 默认标签的改进,我们可以实现更多个性化功能。这对于拥有复杂栏目结构的网站尤为重要。希望这篇文章能帮助您更好地管理和优化您的 Dedecms 网站。