2010-01-09 33 views
2

我的博客主菜單由類別組成,通過wp_list_categories函數顯示。wp_list_categories不顯示當前類別

如果我點擊其中一個類別,當前類別將在類別菜單中突出顯示,並列出該類別內的文章列表。一切安好。

但是,如果我然後單擊一篇文章,類別菜單不再顯示當前類別。任何人都知道我該如何解決這個問題

這裏是我用來在邊欄中生成菜單的代碼。

<?php 
wp_list_categories('child_of=55&sort_column=menu_order&sort_order=asc&title_li='); 
?> 

回答

3

我在wordpress論壇上發現a good hack。它只會顯示一個「當前」類別,但足以滿足我的需求。

<?php 
    if (!is_page() && !is_home() && !is_single()){ 
    $catsy = get_the_category(); 
    $myCat = $catsy->cat_ID; 
    $currentcategory = '&current_category='.$myCat; 
} 

    elseif (is_single()){ 
    $catsy = get_the_category(); 
    $myCat = $catsy[0]->cat_ID; 
    $currentcategory = '&current_category='.$myCat; 
} 

    wp_list_categories('depth=1&title_li=&orderby=id&exclude=1,5,6,19,20,21,22&hide_empty=0'.$currentcategory); 
    ?> 

如果只強調分類1,當你有一個多品類,每帖系統,你可能需要使用this plugin代替(添加.used-cat類在樣式表中,沿着由WordPress提供的.current-cat類)。

1

'parent'不是wp_list_categories的有效參數。

此外,你確定相同的代碼提供類別頁面和帖子頁面的類別列表嗎?代碼可能位於is_category或is_post/is_page塊內。

+0

感謝您的父母錯誤,我刪除它。對於上面的代碼,它位於sidebar.php中。因此,它位於循環之外,但它在archive.php模板中正常工作,而不是在single.php模板中。 (它起作用意味着:當前類別被突出顯示)。 – pixeline 2010-01-10 12:56:07