知识问答
如何在织梦DedeCMS系统中有效调用四级分类栏目?
2025-09-21 13:08:56
来源:互联网转载
在织梦DedeCMS中,调用四级栏目可以使用以下代码:,,``
php,{dede:channel type='top' row='4'},[field:typename/],{/dede:channel},
``在织梦DedeCMS中调用四级栏目,可以通过修改文件和编写特定的标签代码来实现,以下是详细步骤和相关代码示例:
修改文件
1、修改\include\taglib
目录下的channel.lib.php
文件:
将以下代码***替换到channel.lib.php
文件中:
<?php function lib_channel(&$ctag, &$refObj) { global $_sys_globals, $envs, $dsql; $attlist = "typeid|0,reid|0,row|100,col|1,type|son,currentstyle|"; FillAttsDefault($ctag>CAttribute>Items, $attlist); extract($ctag>CAttribute>Items, EXTR_SKIP); $innertext = $ctag>GetInnerText(); $cacheid = trim($cacheid); if ($cacheid != '') { $likeType = GetCacheBlock($cacheid); if ($likeType != '') return $likeType; } $reid = 0; $topid = 0; if (empty($typeid) && $envs['typeid'] != 0) { $typeid = $envs['typeid']; $reid = $envs['reid']; } else { $reid = 0; } if ($type == '' || $type == 'sun') $type = 'son'; if ($innertext == '') $innertext = GetSysTemplets("channel_list.htm"); if ($reid == 0 && $typeid > 0) { $dbrow = $dsql>GetOne("select reid From dede_arctype where id='$typeid' "); if (is_array($dbrow)) $reid = $dbrow['reid']; } $likeType = ''; if ($type == 'top') { $sql = "select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description From dede_arctype where reid=0 And ishidden<>1 order by sortrank asc limit 0,$row"; } else if ($type == "son") { if ($_sys_globals['typeid'] > 0) $typeid = $_sys_globals['typeid']; if ($typeid == 0) { return ''; } $sql = "select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description From dede_arctype where reid='$typeid' And ishidden<>1 order by sortrank asc limit 0,$row"; } else if ($type == "self") { if ($reid == 0) { return ''; } $sql = "select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath,description From dede_arctype where reid='$reid' And ishidden<>1 order by sortrank asc limit 0,$row"; } $needRel = false; $dtp2 = new DedeTagParse(); $dtp2>SetNameSpace("field", "[", "]"); $dtp2>LoadSource($innertext); $dsql2 = clone $dsql; $dsql>SetQuery($sql); $dsql>Execute(); $line = $row; if (ereg(':rel', $innertext)) $needRel = true; if (empty($sql)) return ''; $dsql>SetQuery($sql); $dsql>Execute(); $totalRow = $dsql>GetTotalRow(); $GLOBALS['autoindex'] = 0; for ($i = 0; $i < $line; $i++) { if ($col > 1) $likeType .= "<dl>\r"; for ($j = 0; $j < $col; $j++) { if ($col > 1) $likeType .= "<dd>\r"; if ($row = $dsql>GetArray()) { $row['sonids'] = $row['rel'] = ''; if ($needRel) { $row['sonids'] = GetSonIds($row['id'], 0, false); if ($row['sonids'] == '') $row['rel'] = ''; else $row['rel'] = " rel='dropmenu{$row['id']}'"; } //处理同级栏目中,当前栏目的样式 if (($row['id'] == $typeid || ($topid == $row['id'] && $type == 'top')) && $currentstyle != '') { if ($currentstyle != '') { $linkOkstr = $currentstyle; $row['typelink'] = GetOneTypeUrlA($row); $linkOkstr = str_replace("~rel~", $row['rel'], $linkOkstr); $linkOkstr = str_replace("~id~", $row['id'], $linkOkstr); $linkOkstr = str_replace("~typelink~", $row['typelink'], $linkOkstr); } } $likeType .= "<a href='" . $row['typelink'] . "' class='" . $row['class'] . "'>" . $row['typename'] . "</a>\r"; if ($col > 1) $likeType .= "</dd>\r"; } } if ($col > 1) $likeType .= "</dl>\r"; } return $likeType; }
调用代码示例
顶级栏目调用
{dede:channel type='top' currentstyle="<li class='thisclass'><a href='~typelink~'>~typename~</a></li>"}
二级栏目调用
{dede:channel type='son' currentstyle="<a href='[field:typelink/]' class='depth_2'>[field:typename/]</a>"}
三级栏目调用
{dede:channel type='son' currentstyle="<a href='[field:typelink/]' class='depth_3'>[field:typename/]</a>"}
四级栏目调用(假设四级栏目的顶级栏目ID为4)
{dede:channel type='son' noself='yes'} <a href="[field:typelink/]">[field:typename/]</a><br />{/dede:channel}
表格归纳
栏目级别 | 调用代码 |
顶级栏目 | {dede:channel type='top' currentstyle=" |
二级栏目 | {dede:channel type='son' currentstyle="[field:typename/]"} |
三级栏目 | {dede:channel type='son' currentstyle="[field:typename/]"} |
四级栏目 | {dede:channel type='son' noself='yes'}[field:typename/] |
FAQs
Q1: 如何修改channel.lib.php
文件?
A1: 通过FTP或服务器管理工具登录你的服务器,找到并下载\include\taglib
目录下的channel.lib.php
文件,使用文本编辑器打开并按上述代码进行修改,保存后上传覆盖原文件,确保文件权限正确,以便系统能正常读取。
Q2: 如何确认修改后的调用代码生效?
A2: 完成修改并上传文件后,刷新网站页面查看效果,如果调用代码没有显示预期的栏目结构,请检查代码是否有语法错误,或者重新登录后台更新缓存,确保你使用的模板文件路径和标签位置正确。
下一篇:上海网站开发需要多少钱?