一、首先在functions.php函數(shù)文件中添加以下函數(shù):
- <?php
- function get_category_root_id($cat)
- {
- $this_category = get_category($cat); // 取得當(dāng)前分類
- while($this_category->category_parent) // 若當(dāng)前分類有上級分類時,循環(huán)
- {
- $this_category = get_category($this_category->category_parent); // 將當(dāng)前分類設(shè)為上級分類(往上爬)
- }
- return$this_category->term_id; // 返回根分類的id號
- }
- ?>
二、在需要調(diào)用當(dāng)前分類下的子分類的地方插入以下代碼即可:文章源自網(wǎng)吧系統(tǒng)維護(hù)-http://www.strong-digital.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的開始和結(jié)束標(biāo)簽。文章源自網(wǎng)吧系統(tǒng)維護(hù)-http://www.strong-digital.cn/7812.html 文章源自網(wǎng)吧系統(tǒng)維護(hù)-http://www.strong-digital.cn/7812.html
版權(quán)聲明:文章圖片資源來源于網(wǎng)絡(luò),如有侵權(quán),請留言刪除!!!
評論