2014-03-27 110 views
0

我有一個自定義分類命名爲SM-類別WordPress的:獲取當前子分類

面積
- 區1
- 區2


- 店1
- 店2

在單個自定義帖子頁面中,我想只顯示帖子的當前區域,可以說'區域1'。

get_term_children($term_id, 'sm-category')將檢索所有孩子的列表,但我只想要該帖子的當前孩子。

有沒有解決方案?

在此先感謝

回答

0

比得到的第一個孩子,..

$subcategorys = get_term_children($term_id, 'sm-category'); 
print_r($subcategorys[0]); // The first entry 
+0

啊謝謝!如果我想要獲取存檔頁面中每個帖子的當前區域,該怎麼辦? – petros

+0

http://codex.wordpress.org/Function_Reference/get_the_category –

+0

我的意思是在自定義帖子存檔頁面。 get_the_category僅適用於普通帖子嗎?不適用於自定義帖子。我錯了嗎? – petros