在网站内容管理系统(CMS)中,Dedecms 是一个非常受欢迎的选择。最近我在对个人站点的栏目进行扩展和细分时,遇到了一个问题:希望某些栏目不在首页的最新文章列表中显示。虽然 Dedecms 的 arclist 标签支持 typeid 属性来指定需要显示的栏目 ID,但如果栏目过多,手动设置所有栏目 ID 将变得繁琐且难以维护。
于是,我开始思考是否可以通过添加 notypeid 属性来实现这一功能。经过一番研究和测试,我发现 Dedecms 默认并不支持 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'}
通过这种方式,您可以轻松地从首页的文章列表中排除指定栏目的内容,从而更好地管理复杂的内容显示需求。
这种方法对于栏目较多、内容显示逻辑复杂的网站来说尤为实用。希望这篇文章能帮助到正在使用 Dedecms 的朋友们!