[Typecho] Gets the parent class name?

Source: Internet
Author: User
For example, there are 2 parent class A, B
Subcategories of 4 were A-1, A-2, B-1, B-2
I want to get the parent category name in the sub-category article: What should A or B do?

Reply content:

For example, there are 2 parent class A, B
Subcategories of 4 were A-1, A-2, B-1, B-2
I want to get the parent category name in the sub-category article: What should A or B do?

$this->categories;You can output all current classifications, and then you can go to the database to read them yourself. Look forward to a better approach.

//获取顶级分类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'];    }}

See www.sisi321.com

I know that, too.
The problem is I just need to output the parent's name A or b separately

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.