欢迎访问织梦学习网,加群!!!!!!!!!!!!!!!!
当前位置:主页 > 安装使用 >

dede 子栏目获取上级、顶级栏目的名字和链接

2016-07-16 dedecms安装使用 dede,子,栏目,获取,上级,、,顶级,栏,目的,名字,
DEDE根目录/include/taglib/下找到channel.lib.php文件找到   else if($type=='self') { if($reid==0) return ''; $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath From `dede_arctype` where reid='$reid' And ishidden<>1 order by sortrank asc limit 0, $line "; }   然后,在此段代码下加入如下代码,为{dede:channel}添加父级(parent)栏目属性   else if($type=='parent') { $sql = "Select id,typename,typedir,isdefault,ispart,defaultname,namerule2,moresite,siteurl,sitepath From `dede_arctype` where id='$reid' AND ishidden<>1 order by sortrank asc limit 0, $line "; }   然后用下面的就行了   <!--调用当前栏目的顶级栏目名称--> {dede:channel type='parent' } [field:typename/] {/dede:channel}   dede 子栏目获取上级、顶级栏目的名字和链接   上面的方法当 当前栏目就是顶级栏目时候会失效,所以需要用到下面的方法【非无限子栏目】   {dede:field.typeid runphp='yes'}$ID = @me; $sql = "SELECT * FROM `dede_arctype` WHERE id=$ID";$query = mysql_query($sql);$row=mysql_fetch_array($query); $relID = "$row[reid]"; if($relID == 0) {@me = $row[typename];}else{$sql = "SELECT `typename` FROM `dede_arctype` WHERE id=$relID";$query = mysql_query($sql);$row=mysql_fetch_array($query); @me = $row[typename];}{/dede:field.typeid}   下面是顶级栏目的ID【非无限子栏目】   {dede:field.typeid runphp='yes'}$ID = @me; $sql = "SELECT * FROM `dede_arctype` WHERE id=$ID";$query = mysql_query($sql);$row=mysql_fetch_array($query); $relID = "$row[reid]"; if($relID == 0) {@me = $row[id];}else{$sql = "SELECT `id` FROM `dede_arctype` WHERE id=$relID";$query = mysql_query($sql);$row=mysql_fetch_array($query); @me = $row[id];}{/dede:field.typeid}     下面是无限子栏目获取顶级栏目资料的方法,不过下面的实例是获取顶级栏目下,的第二个栏目的方法,不过要获取顶级栏目的话,更简单,所做修改即可。   {dede:field.typeid runphp='yes'} $ID = @me; $sql = "SELECT * FROM `dede_arctype` WHERE id=$ID"; $query = mysql_query($sql); $row=mysql_fetch_array($query); $relID = $row[reid]; $jishu; while($relID != 0){ $jishu = $row[id]; $sql = "SELECT * FROM `dede_arctype` WHERE id=$relID"; $query = mysql_query($sql); $row=mysql_fetch_array($query); $relID = $row[reid]; } $sql = "SELECT * FROM `dede_arctype` WHERE id=$jishu"; $query = mysql_query($sql); $row=mysql_fetch_array($query); @me = $row[arcpic]; {/dede:field.typeid}