dedeCMS子欄目獲取上級、頂級欄目的名字和鏈接
在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}
*