作者:狐灵科技 | 2020-02-15 22:34 |点击:
/**
* 获取顶级栏目相关信息
*
* @access public
* @param string $tid 栏目id
* @param string $field 栏目字段
* @return string
*/
if ( ! function_exists('getToptype'))
{
function getToptype($tid,$field)
{
global $dsql,$cfg_Cs;
if(!is_array($cfg_Cs))
{
require_once(DEDEDATA."/cache/inc_catalog_base.inc");
}
if(!isset($cfg_Cs[$tid][0]) || $cfg_Cs[$tid][0]==0)
{
$topid = $tid;
}
else
{
$topid = GetTopid($cfg_Cs[$tid][0]);
}
$row = $dsql->GetOne("SELECT * FROM `dede_arctype` WHERE id=$topid");
if($field=='id') return $topid;
if($field=='typeurl' || $field=='typelink') return GetOneTypeUrlA($row);
return $row[$field];
}
}
/**
* 获取当前栏目相关信息
*
* @access public
* @param string $tid 栏目id
* @param string $field 栏目字段
* @return string
*/
if ( ! function_exists('getCurtype'))
{
function getCurtype($tid,$field)
{
global $dsql;
$row = $dsql->GetOne("SELECT * FROM `dede_arctype` WHERE id=$tid");
if($field=='id') return $tid;
if($field=='typeurl' || $field=='typelink') return GetOneTypeUrlA($row);
return $row[$field];
}
}
/**
* 获取上级栏目相关信息
*
* @access public
* @param string $tid 栏目id
* @param string $field 栏目字段
* @return string
*/
if ( ! function_exists('getRetype'))
{
function getRetype($tid,$field)
{
global $dsql;
$typeid = $tid;
$query = "SELECT reid FROM `dede_arctype` where id = $typeid";
$rs = $dsql->GetOne($query);
$reid = $rs['reid'];
$query2 = "SELECT * FROM `dede_arctype` where id = $reid";
$row = $dsql->GetOne($query2);
if($field=='id') return $tid;
if($field=='typeurl' || $field=='typelink') return GetOneTypeUrlA($row);
return $row[$field];
}
}
模板里调用标签写法
需要哪个字段,就对应的填上字段名即可
获取顶级栏目相关信息 {dede:field.typeid function=getToptype(@me,typename)/}
获取当前栏目相关信息 {dede:field.typeid function=getCurtype(@me,typename)/}
获取上级栏目相关信息
{dede:field.typeid function=getRetype(@me,typename)/}
不喜欢添加自定义方法的同学可以试试这样
{dede:field.typeid runphp=yes}global $dsql;$row = $dsql->GetOne("SELECT * FROM dede_arctype WHERE id=@me");$reid = "$row[reid]"; $topid = "$row[topid]";if($reid == 0) @me = $row[content];else $row = $dsql->GetOne("SELECT * FROM dede_arctype WHERE id=$topid");@me = $row[content];{/dede:field.typeid}
获取顶级的是topid
获取上级的是reid