I’ve searched and can’t find the answer for my situation.
I have a category dropdown menu item, but cannot seem to get the code to generate “current-cat-parent” for the parent menu item when a submenu item is clicked.
I want to do this so I can highlight the parent menu item when a submenu child is clicked.
Here’s my code:
<li class="cat-item">
<a href="#">Work</a>
<ul class="children">
<?php wp_list_categories("exclude=$blog_ID&title_li=");('orderby=name&title_li=');
$this_category = get_category($cat);
if (get_category_children($this_category->cat_ID) != "") {
echo "<ul>";
wp_list_categories('orderby=id&show_count=0&title_li=
&use_desc_for_title=1&child_of='.$this_category->cat_ID);
echo "</ul>";
}
?>
</ul>
</li>
I think I have the right css, but because the “current-cat-parent” code isn’t being generated when I click on a subcategory, the css can’t style the parent menu item.
Any help would be greatly appreciated!
]]>I’m a newb and have a question about highlighting the current parent menu item in a dropdown menu. I’m using wordpress as a CMS.
The menu section in question is like this:
Top level menu item:
Work
Dropdown submenu categories:
Interactive
Microsite
Email
Print
Collateral
Direct Mail
Outdoor
Broadcast
I have it now that when a user clicks on, let’s say, ‘Print’, ‘Print’ stays highlighted…BUT I want both ‘Print’ AND ‘Work’ to stay highlighted. I simply cannot figure out how to get the top level menu item ‘Work’ to stay highlighted too.
Also, if the user clicks on a post within a submenu category like ‘Print’ for example, I’d like for ‘Print’ and ‘Work’ to stay highlighted.
So basically, whenever a user is anywhere within the ‘Work’ section, on a subcategory or a post within a subcategoy, I’d like ‘Work’ to stay highlighted.
Here’s the navigation code from header.php:
<!-- Navigation -->
<ul class="sf-menu">
<li<?php
if (is_home())
{
echo " id=\"current\"";
}?>>
<a href="<?php bloginfo('url') ?>">Home</a>
</li>
<li>
<a>Work</a>
<ul>
<?php wp_list_categories("exclude=$blog_ID&title_li="); ?>
</ul>
</li>
<!-- <?php wp_list_categories("include=$blog_ID&title_li="); ?> -->
<li<?php
if (is_page('About'))
{
echo " id=\"current\"";
}?>>
<a href="<?php bloginfo('url') ?>/about">About</a>
</li>
<li<?php
if (is_page('Contact'))
{
echo " id=\"current\"";
}?>>
<a href="<?php bloginfo('url') ?>/contact">Contact</a>
</li>
</li>
</ul>
</div>
Here’s the css:
/* Navigation Highlights */
.sf-menu li.current-cat a, li.current_page_item a {font-weight:bold;color:#e2007d;}
#current a {font-weight:bold;color:#e2007d;}
.sf-menu a:hover{color:#e2007d;}
.sf-menu li.current-cat a{font-weight:bold;color:#e2007d;}
.sf-menu li.current-cat a:hover{font-weight:bold;color:#e2007d;
I figured out how to get other pages to stay highlighted, but I just can’t solve the riddle of how to get ‘Work’ to stay highlighted when on a submenu item.
Here’s a link to the site: https://newsite.blairshapiro.com
Been racking my brain for days, any help would be GREATLY appreciate.
Thanks!
]]>For example, my top menu item is called ‘Work’ and it has sublinks like ‘Interactive’ ‘Print’ ‘Email’ etc. When user has clicked on, say, ‘Email’ I want both ‘Email’ and its parent menu item ‘Work’ to both stay highlighted.
I now have it so the sublink stays highlighted, but I cannot get the parent menu item ‘Work’ to stay highlighted. Here’s the curent css:
.sf-menu a:hover{color:#e2007d;}
.sf-menu li.current-cat a{font-weight:bold;color:#e2007d;}
.sf-menu li.current-cat a:hover{font-weight:bold;color:#e2007d;}
I have tried the following css to get the parent item ‘Work’ to stay highlighted, but it’s not working:
.sf-menu li.current-cat-parent a{font-weight:bold;color:#e2007d;}
.sf-menu li.current_page_parent a{font-weight:bold;color:#e2007d;}
.sf-menu li.current_page_ancestor a{font-weight:bold;color:#e2007d;}
My first goal is to get ‘Work’ to stay highlighted when in a subcategory. After that, I’d like to get ‘Work’ to ALSO stay highlighted if user in viewing a post from one of the subcategories under ‘Work’.
Here’s a link to the test site to see it: https://newsite.blairshapiro.com
Any help would be GREATLY appreciated!
]]>For example, my top menu item is called ‘Work’ and it has sublinks like ‘Interactive’ ‘Print’ ‘Email’ etc. When user has clicked on, say, ‘Email’ I want both ‘Email’ and its parent menu item ‘Work’ to both stay highlighted.
I now have it so the sublink stays highlighted, but I cannot get the parent menu item ‘Work’ to stay highlighted. Here’s the curent css:
.sf-menu a:hover{color:#e2007d;}
.sf-menu li.current-cat a{font-weight:bold;color:#e2007d;}
.sf-menu li.current-cat a:hover{font-weight:bold;color:#e2007d;}
I have tried the following css to get the parent item ‘Work’ to stay highlighted, but it’s not working:
.sf-menu li.current-cat-parent a{font-weight:bold;color:#e2007d;}
.sf-menu li.current_page_parent a{font-weight:bold;color:#e2007d;}
.sf-menu li.current_page_ancestor a{font-weight:bold;color:#e2007d;}
My first goal is to get ‘Work’ to stay highlighted when in a subcategory. After that, I’d like to get ‘Work’ to ALSO stay highlighted if user in viewing a post from one of the subcategories under ‘Work’.
Here’s a link to the test site to see it: https://newsite.blairshapiro.com
Any help would be GREATLY appreciated!
]]>To put this another way, let’s say I have a category/post hierarchy like this:
No matter which category, or even if I click on the article, I want the word “Articles” to be styled to show a “current” state.
Any idea how I could do this dynamically?
Thanks,
Gary
since I need to use wp_list_categories in a site’s navigation, I have realized what I consider a bug in this function: it does not allow for highlighting the current category when I’m looking at a post.
I’m not fond of fiddling with core files, so is there any way I can write a plugin or a functions.php function to add this “current-cat” style to the category list?
]]>