Home > Backend Development > PHP Tutorial > [typecho]获取 父级分类 名称?

[typecho]获取 父级分类 名称?

WBOY
Release: 2016-06-06 20:41:41
Original
1597 people have browsed it

比如有2个父级分类 A, B
子分类4个分别是A-1, A-2, B-1, B-2
我想在子分类的文章里, 获取其父分类名称:A或B应该怎么做?

回复内容:

比如有2个父级分类 A, B
子分类4个分别是A-1, A-2, B-1, B-2
我想在子分类的文章里, 获取其父分类名称:A或B应该怎么做?

$this->categories;可以输出所有当前分类,然后可以自己去数据库读取。期待有更好的方法。

<code>//获取顶级分类
function topcategory($category) {
    $db = Typecho_Db::get(); 
    $prefix = $db->getPrefix(); 
    $rs = $db->fetchRow($db->select()->from($prefix.'metas')->where('slug = ?', $category)->limit(1));

    if($rs['parent']==0){
        return $rs['slug'];
    }
    else {
        $rs2 = $db->fetchRow($db->select()->from($prefix.'metas')->where('mid = ?', $rs['parent'])->limit(1));
        return $rs2['slug'];
    }
}
</code>
Copy after login

详见www.sisi321.com

这个我也知道的
问题是我只需要 单独输出 父级的名称A或B

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template