织梦cms子栏目获取父级栏目名称教程
织梦cms子栏目获取父级栏目名称教程,下面是调用顶级栏目名称的详细代码方法,一起来学习吧:方法一:
{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“; if($relID == 0) {@me = $row;}
else{$sql = “SELECT `typename` FROM `dede_arctype` WHERE id=$relID”;
$query = mysql_query($sql);$row=mysql_fetch_array($query);
@me = $row;}{/dede:field.typeid}
这个方法语句有些长。
方法二:
{dede:field.titlerunphp='yes'}
list($toptype,$sontype)=split('/',@me);@me=$toptype;
{/dede:field.title}
方法三:
{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"; $topID="$row";
if($relID == 0) {@me = $row;}
else{$sql = "SELECT `typename` FROM `dede_arctype` WHERE id=$topID";
$query = mysql_query($sql);$row=mysql_fetch_array($query);
@me = $row;}{/dede:field.typeid}
方法四(推荐):
打开include/helpers/extend.helper.php,添加一个函数:
/**
*获取指定栏目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,添加一个函数:
/***获取指定栏目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']);}}
文档来源:网络转载http://www.adminbuy.cn/dedecmsjc/6607.html
页:
[1]