Forums

[resolved] Show the current category inside a category menu (4 posts)

  1. pixeline
    Member
    Posted 2 years ago #

    Hi!

    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 (the .current_cat css class is not added to the current category). 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&parent=55&sort_column=menu_order&sort_order=asc&title_li=');
    ?>
  2. alchymyth
    The Sweeper
    Posted 2 years ago #

    as a post could have several categories, i would try and write a function to highlight each of these (rough outline of the idea):
    get the list of categories into an array (with 'echo=0');
    get the categories of the post (get_category($post->ID)- or so, syntax not checked);
    sort through the list and add the current-cat style to the matching list item(s);
    echo each array item.

    call this function in single.php instead of wp_list_categories ;-)

  3. alchymyth
    The Sweeper
    Posted 2 years ago #

  4. alchymyth
    The Sweeper
    Posted 2 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic