views:

343

answers:

2

My blog's main menu is made of the categories, displayed via the wp_list_categories function.

If i click on one of the categories, the current category is highlighted in the category menu, and the list of articles inside that category are listed. Everything is fine.

But if i then click on one article, the Category menu does not show the current category anymore. Anyone knows how i could fix that?

Here is the code i use to generate the menu in the sidebar.

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

'parent' isn't a valid argument for wp_list_categories.

Also, are you sure the same code is providing the category list for both the category page and the post page? The code might be within an is_category or is_post/is_page block.

adam
thanks for the parent error, i removed it.As for the code above, it sits in sidebar.php. Therefore, it sits outside the loop, but it works fine in the archive.php template, not in the single.php template. (it works meaning: the current category is highlighted).
pixeline
A: 

I found a good hack on the wordpress forum. It will only show one "current" category but it's enough for my needs.

<?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);
    ?>

If only highlighting 1 category when you have a multi-category-per-post system, you might want to use this plugin instead (add a .used-cat class in your stylesheet, alongside the .current-cat class provided by wordpress).

pixeline