• Hello,

    I have been having problems with getting the current categories in my drop down menu to highlight when I am in that category.

    I can get pages to highlight fine but not categories.

    After looking in my source code I have found this for the categories:

    <li class="<strong>cat-item cat-item-1</strong>"><a href="domain.com/cat" title="">Category Name</a>
    <ul class='children'>
    	<li class="<strong>cat-item cat-item-4</strong>"><a href="domain.com/subcat1" title="">Subcat 1</a>
    </li>
    	<li class="<strong>cat-item cat-item-5</strong>"><a href="domain.com/subcat2" title="">Subcat 2</a>
    </li>

    As you can see both the top level and child categories have classes. So when I use this code in my header.php:

    <?php if (is_category()) { echo 'class="current_page_item"'; } ?><?php wp_list_categories("title_li=&exclude=50"); ?>

    it doesn’t highlight the category when im on the top level category page as it now produces this source code:

    <strong><li class="current_page_item"></strong> <li class="<strong>cat-item cat-item-1 current-cat</strong>"><a href="domain.com/cat" title="">Category Name</a>

    Ok I was about to ask how the hell do I highlight the categories. But I have just realised that wordpress seems to automatically ass “current-cat” to the category being viewed. Plus, if the current category being viewed is a child then is also adds “current-cat-parent” to the top level category while still adding “current-cat” to the child.

    So I think adding some css will make this work? I’ll try that now.

    I still think the class such as “cat-item cat-item-1” is not needed. Plus why is wordpress automatically adding current classes for categories and not for pages?

    Seems strange.

Viewing 1 replies (of 1 total)
  • Thread Starter scdwb

    (@scdwb)

    I’m getting somewhere now. I have added this to my css:

    current-cat a{background:#444;}

    And now the child category is highlighted in my drop down when I am in that category. This is brilliant, however, for some reason when I have selected the top level category everything is highlighted. All the child categories and the top level category.

    The strange thing is that my “current-cat” is not in any of the li classes for the child categories and the top level category has a class of “current-cat-parant”.

    Does anyone know why all the categories are highlighted when on the top level cat page?

    Thanks!

Viewing 1 replies (of 1 total)
  • The topic ‘Why does the category list have a class?’ is closed to new replies.