Hello dpolcino,
On a single post page, there are no parents or children to add classes to.
Posts do not support assignment to parents like pages and categories do.
The best you can do is target the category by id which is added to a class like ‘cat-item-11’.
Hope this helps.
Cheers.
Thanks, yes, I figured that was the case.
Can you explain this a little more if you get a chance “..category by id which is added to a class like ‘cat-item-11’?
I’m open to hardcoding for these sections, just haven’t figured out quite how to do it!
Certainly,
If you look at the menus output when you are on a single post page, you will see in the li items there is a class like cat-item-11 for example.
<ul class="parent-sidebar-menu"> <li class="cat-item cat-item-1"><a href="http://wordpress.loc/category/uncategorized/" title="View all posts filed under Uncategorized">Uncategorized</a>
</li>
<ul class="child-sidebar-menu"> <li class="cat-item cat-item-11"><a href="http://wordpress.loc/category/uncategorized/under-uncategorized/" title="View all posts filed under Under Uncategorized">Under Uncategorized</a>
</li>
</ul><!-- End #child-sidebar-menu --></ul>
Each category list item is given a class with the id of the category. So if the link if for a category with an id or 11 the class will be cat-item-11.
The category id will not change from post to post so you can add css once and it will carry throughout the site.
Thanks! I think I’m getting somewhere. I put this in my template’s header file and it does generate what I need, it’s just not applying to the menu item. Probably a small error on my part (not quite targeting the class depth?):
<?php
if (in_category(‘noise’)){ $current = ‘page-item-17’; }
elseif (in_category(‘studio-know-how’)){ $current = ‘cat-item-26’; }
elseif (in_category(‘cool-gear’)){ $current = ‘cat-item-27’; }
elseif (in_category(‘the-sessions’)){ $current = ‘cat-item-28’; }
?>
<style type=”text/css”>
.<?php echo $current; ?> {
color: #000 !important;
}
</style>
Here is something to try.
Change your style code to this:
<style type="text/css">
.<?php echo $current; ?> a,
.<?php echo $current; ?> a:visited{
color: #000 !important;
}
</style>
Hope this helps
Hah was just doing something similar:
<?php
if (in_category(‘noise’)){ $current = ‘page-item-17’; }
elseif (in_category(‘studio-know-how’)){ $current = ‘cat-item-26’; }
elseif (in_category(‘cool-gear’)){ $current = ‘cat-item-27’; }
elseif (in_category(‘the-sessions’)){ $current = ‘cat-item-28’; }
?>
<style type=”text/css”>
#advanced_sidebar_menu_category-2 .<?php echo $current; ?> a {
color: #000 !important;
}
</style>
Take that WordPress!
Thanks Mat.
Lol.
“Take that WordPress”. I love it! It may be my new tag line for the day.
Cheers!
yup, yours works too of course and is better syntax.
caveat for anyone wanting to try this. Don’t add top level categories or else they’ll all hilite!
resolved