2011-04-28 38 views
1

我試圖創建自定義分類下面的菜單結構:WordPress的自定義分類親子導航菜單

CAT 1 
-SubCat1 
-SubCat2 

CAT 2 
CAT 3 
CAT 4 

我想實現的是,當我點擊一個子類別(SubCat1例如)我目前的導航結構應該保持不變,並且粗體顯示當前的子文件夾。 當我點擊另一個父類別時,它的子類別應該出現,並且只有其他父類別(不是所有帶子類型的貓類)。

我的問題有以下幾點:

我管理的一個父類,當點擊創建子導航菜單,但它只能顯示當前和菜單中的子級別分類,不使用其他主要類別此代碼:

<?php 
$taxonomy  = $tax; 
$orderby  = 'name'; 
$show_count = 1;  // 1 for yes, 0 for no 
$pad_counts = 0;  // 1 for yes, 0 for no 
$hierarchical = 1;  // 1 for yes, 0 for no 
$title  = ''; 
if (get_term_children($term->term_id, $tax) != null) { 
$child = $term->term_id; 
} else { 
$child = ''; 
} 
$args = array(
    'taxonomy'  => $taxonomy, 
    'orderby'  => $orderby, 
    'show_count' => $show_count, 
    'pad_counts' => $pad_counts, 
    'hierarchical' => $hierarchical, 
    'title_li'  => $title, 
    'child_of'  => $child, 
    'current_category' => 0 

); 
?> 
<? if (get_term_children($term->term_id, $tax) != null) { ?> 
<h3><?php echo $term->name; ?> Templates</h3> 
<? } ?> 
<?php 
wp_list_categories($args); ?> 

問題出在上面的代碼中,當我點擊一個子類別時,所有的父類別/子類別都會再次顯示。

我希望能夠保持在同一個結構,當瀏覽任何一個大類別的子類別,並加上粗體字體到我正在瀏覽的子類別。

如果這對某人有意義,請幫忙。

感謝,

回答

0

我會做的就是通過與0父的分類,然後在顯示他們做get_term_children功能的環路創建一個自定義查詢循環。我相信這是創建這樣的最佳方式。這是我在我的插件中完成的工作,它使我可以有更多的定製。

相關問題