Why does the category list have a class?
-
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.
- The topic ‘Why does the category list have a class?’ is closed to new replies.