# dedecms文章页、列表页如何调用当前栏目的顶级栏目名称及链接

*Published:* 2023-11-21
*Author:* 客服001

#### 温馨提醒

如果文章内容或图片资源失效，请留言反馈，我们会及时处理，谢谢

本文最后更新于2023年11月21日，已超过 180天没有更新



打开include/helpers/extend.helper.php文件，在文件中添加函数：

```
/*  获取<a class="tag_link" href="https://www.xarjtc.com/tag/%e9%a1%b6%e7%ba%a7%e6%a0%8f%e7%9b%ae" target="_blank" title="查看顶级栏目此标签更多文章"><abbr title="">顶级<a class="tag_link" href="https://www.xarjtc.com/tag/%e6%a0%8f%e7%9b%ae" target="_blank" title="查看栏目此标签更多文章"><abbr title="">栏目</abbr></a></abbr></a>相关信息
 * 鹏程木业网 https://www.360muye.cn/
 * @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'];//栏目内容
}
}
```

在底层模板调用：

```
{dede:field.typeid function="gettoptype(@me,typename)"/}  //栏目名称
```

栏目链接、seo标题、栏目描述、栏目内容等同样的道理，只需要更换typename即可。例如栏目链接：

```
{dede:field.typeid function="gettoptype(@me,typeurl)"/}   //栏目链接
```