标签 打开文件 \\\\include\\\\extend.func.php,在最下方添加以下代码:
/**
* 获取顶级栏目相关信息
*
* @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=='typename') return $row['typename'];//栏目名称
if($field=='typeurl') return GetOneTypeUrlA($row);//栏目链接
if($field=='typenamedir') return $row['typenamedir'];//栏目英文名称
if($field=='seotitle') return $row['seotitle'];//栏目SEO标题
if($field=='description') return $row['description'];//栏目描述
if($field=='content') return $row['content'];//栏目内容
}
}
/**
* 获取当前栏目相关信息
*
* @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=='typename') return $row['typename'];//栏目名称
if($field=='typeurl') return GetOneTypeUrlA($row);//栏目链接
if($field=='typenamedir') return $row['typenamedir'];//栏目英文名称
if($field=='seotitle') return $row['seotitle'];//栏目SEO标题
if($field=='description') return $row['description'];//栏目描述
if($field=='content') return $row['content'];//栏目内容
}
}
/**
* 获取上级栏目相关信息
*
* @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=='typename') return $row['typename'];//栏目名称
if($field=='typeurl') return GetOneTypeUrlA($row);//栏目链接
if($field=='typenamedir') return $row['typenamedir'];//栏目英文名称
if($field=='seotitle') return $row['seotitle'];//栏目SEO标题
if($field=='description') return $row['description'];//栏目描述
if($field=='content') return $row['content'];//栏目内容
}
}
标签 {dede:field.typeid function=getToptype(@me,typename)/}
标签 如果是获取当前栏目的信息,则可以使用:
标签 {dede:field.typeid function=getCurtype(@me,typename)/}
标签 对于上级栏目的信息,相应的代码为:
标签 {dede:field.typeid function=getRetype(@me,typename)/} 通过以上方法,开发者能够更灵活地控制和显示网站各栏目的相关内容,从而提升用户体验和网站的专业性。这种方法不仅适用于Dedecms系统,也可以作为参考应用于其他类似的CMS平台。