《wordpress不同分類調用當前子分類》要點:
本文介紹了wordpress不同分類調用當前子分類,希望對您有用。如果有疑問,可以聯系我們。
wordpress不同分類調用當前子分類,這種需求在一些企業網站中經常見到,例如進入產品中心目錄希望側邊欄顯示產品中心目錄下面的子分類,實現這種效果,我們必要通過兩步驟實現:
1、獲取當前目錄的ID或別號;
2、使用某個分類下面的子分類標簽完成挪用.
以下是實現辦法:
1、獲取當前目錄的ID;你必要在函數文件functions.php中添加以下獲取當前分類目錄ID的代碼:
//獲取以后分類ID?
function get_category_root_id($cat)?? {?
$this_category = get_category($cat);? // 取適合前分類?
? while($this_category->category_parent)?? // 若當前分類有上級分類時,輪回?
? {?
?? $this_category = get_category($this_category->category_parent);?? // 將當前分類設為下級分類(往上爬?
? }?
? return $this_category->term_id; // 返回根分類的id號??
}?
2、以上代碼返回的當前目錄的ID為:get_category_root_id($cat),下一步我們只必要通過wp_list_cats標簽在參數中添加child_of的值為 get_category_root_id($cat) 就可以了,所以調用標簽如下:
<必修php wp_list_cats('child_of=' . get_category_root_id($cat) . '&depth=1&hide_empty=0&hierarchical=1&optioncount=1');必修>?
《wordpress不同分類調用當前子分類》是否對您有啟發,歡迎查看更多與《wordpress不同分類調用當前子分類》相關教程,學精學透。維易PHP學院為您提供精彩教程。
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/13784.html