Support » Themes and Templates » Navigation: Current Category Highlight

  • Hi there,

    I’ve made fairly thorough searches of both this forum and google, and still haven’t found exactly what I’m looking for.

    Let me explain my situation:

    I currently have my main site navigation displaying my top-level categories (there are three of them) and my two pages (5 navigation items altogether).

    Now, I’m using the ‘current-cat’ and ‘current_page_item’ classes to facilitate navigation highlights.

    Here is my problem:

    Using ‘current-cat’ and ‘current_page_item’ works well for the two single pages, and works for the categories but only while one remains at the parent category archive page.

    What I want to be able to do is to have the navigation highlights persist when viewing subcategories or single articles within a given category.

    Does anyone know how this might be implemented?
    Or is there a better way for me to structure my content?

    I’m open to all and any suggestions at this point.

    Kind Regards,


Viewing 9 replies - 1 through 9 (of 9 total)
  • Some more thoughts on this:

    I was thinking I could use the PHP function ‘stristr()’ to check the URL (‘get_category_link($cat)’) against a hard-coded string containing the name of the parent category, but then I’d have to abandon using ‘wp_list_cats’ and hard-code the other category navigation items.


    As much as I don’t like the idea of bumping posts up, I’m bumping this up.

    Surely someone has come up against this problem before?
    And if they haven’t, I’m sure the solution would be of benefit to many.

    I’m bumping this again…

    I have the same exact problem, and haven’t found a solution yet – will keep you updated.

    Thanks! It’s still got me stumped!

    Maybe, a solution… This works for me. It gives the ID of the Category… just put this in the “functions.php” in your themes folder. It works inside and outside the Loop, and even in the single.php.

    function gib_kategorie_ID()
    global $wpdb;
    $diekat = get_query_var(‘cat’);
    if ($diekat < 1)
    $name = get_query_var(‘name’);
    $id = $wpdb->get_var(“SELECT ID FROM $wpdb->posts WHERE post_name = ‘$name'”);
    $kategorie = mysql_query(“SELECT category_id FROM $wpdb->post2cat WHERE post_id = ‘$id’ ORDER BY category_id ASC LIMIT 1”);
    $diekat = @mysql_result($kategorie, 0);
    return $diekat;

    ok, now it should work 🙂

    I have the exact same request as danwillis: I want the parent category to be given a CSS class when a child category is selected.

    There are many plugins to add a class to the active category, but none of them add anything to the parent. The closest I’ve come to a solution is Navigo, which does what I want, but with pages instead of categories.

    If I click on a child category, Navigo adds “level1” to the ul containing the main links, “level1active” to the parent li, level2 to the child ul and “level2active” to the selected child category. I can style each level of the menu – it’s wonderful. Unfortunately it doesn’t work for categories… maybe someone can deconstruct the php?

    Peter, I added your code to the functions.php and nothing happened. Does it need to be translated to work?



    This is a problem for me too, and I have found no solution although I thoroughly searched and read through a lot of topics.

    So to sketch the problem for onlookers, this is about the output of wp_list_cats. Currently, class=\\"current_cat\\" is only added when browsing a category archive. When viewing a single post in a category, wp_list_cats provides no way to style the category the current post is in differently. It would make overwhelming sense, however, if the current category would get class=\\"current_cat\\" in that case too.

    Anyone who can hand me a solution deserves eternal praise, ’cause this problem is really maddening! (The solution given by peterschink above holds only for archives; I believe this was fixed in 2.1 anyway. The problem stays for single posts (and maybe also subcategories, haven’t tried that).

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Navigation: Current Category Highlight’ is closed to new replies.