For example there are 2 parent classification A, B Sub-classification 4 are A-1, A-2, B-1, B-2 I want to get the parent category name in the sub-classification article: what Should A or B do? For example, there are two parent classes A and B.
Sub-classification 4 are A-1, A-2, B-1, B-2
I want to get the parent category name in the subcategory article: A or B. What should I do?
Reply content:
For example, there are two parent classes A and B.
Sub-classification 4 are A-1, A-2, B-1, B-2
I want to get the parent category name in the subcategory article: A or B. What should I do?
$this->categories;You can output all the current categories and then read them from the database. We look forward to a better method.
// Obtain the top-level category 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'];}
For details, see www.sisi321.com.
I also know this.
The problem is that I only need to output the parent name A or B separately.