1
2
3
4
5
6
7
{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}
这个方法语句有些长。
方法二:
1
2
3
{dede:field.title runphp='yes'}
list($toptype,$sontype)=split('/',@me);@me=$toptype;
{/dede:field.title}
方法三:
1
2
3
4
5
6
7
8
{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]"; $topID="$row[topid]";
if($relID == 0) {@me = $row[typename];}
else{$sql = "SELECT `typename` FROM `dede_arctype` WHERE id=$topID";
$query = mysql_query($sql);$row=mysql_fetch_array($query);
@me = $row[typename];}{/dede:field.typeid}
方法四(推荐):
打开include/helpers/extend.helper.php,添加一个函数:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/**
* 获取指定栏目id的顶级栏目的名称
*
* @return string
*/
if ( ! function_exists('getTopChannelName'))
{
function getTopChannelName($id) {
global $dsql;
$typeinfo = $dsql->GetOne("SELECT * FROM `dede_arctype` WHERE id='{$id}'");
if($typeinfo['reid']==0) return $typeinfo['typename'];
else return getTopChannelName($typeinfo['reid']);
}
}
在列表页这么使用:{dede:field name='id' function='getTopChannelName(@me)'/}
在内容页这么使用:{dede:field name='typeid' function='getTopChannelName(@me)'/}
附带获取顶级栏目的url:
打开include/helpers/extend.helper.php,添加一个函数:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/**
* 获取指定栏目id的顶级栏目的url
*
* @return string
*/
if ( ! function_exists('getTopChannelUrl'))
{
function getTopChannelUrl($id) {
global $dsql;
$typeinfo = $dsql->GetOne("SELECT * FROM `dede_arctype` WHERE id='{$id}'");
if($typeinfo['reid']==0) return GetOneTypeUrlA($typeinfo);
else return getTopChannelUrl($typeinfo['reid']);
}
}
使用方法同上。