一、首先在functions.php函數(shù)文件中添加以下函數(shù):
- <?php
- function get_category_root_id($cat)
- {
- $this_category = get_category($cat); // 取得當前分類
- while($this_category->category_parent) // 若當前分類有上級分類時,循環(huán)
- {
- $this_category = get_category($this_category->category_parent); // 將當前分類設為上級分類(往上爬)
- }
- return$this_category->term_id; // 返回根分類的id號
- }
- ?>
二、在需要調用當前分類下的子分類的地方插入以下代碼即可:文章源自網(wǎng)吧系統(tǒng)維護-http://www.ykday.cn/7812.html
- <?php
- wp_list_categories("child_of=".get_category_root_id(the_category_ID(false)).
- "&depth=0&hide_empty=0&title_li=");
- ?>
這里要注意的是,在插入functions.php函數(shù)時需要看清楚PHP的開始和結束標簽。文章源自網(wǎng)吧系統(tǒng)維護-http://www.ykday.cn/7812.html 文章源自網(wǎng)吧系統(tǒng)維護-http://www.ykday.cn/7812.html
版權聲明:文章圖片資源來源于網(wǎng)絡,如有侵權,請留言刪除!!!
評論