Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I need to add a "has-children" class to the tag if the current page's or post's menu item in fact has children.

As this "logic" has to work with Pages, Posts, Categories etc. menu items it seems it is not easy to find out.

Thanks in advance!

Edit: I am not sure I explained good enough: I need to add "has-children" not if the current page is a page-child but only if the current page's menu-item is a menu-item-child...

share|improve this question
add comment

2 Answers

There is a body_class filter, if memory serves. That would be the right one to use.

share|improve this answer
    
As far as I know that doesn't help with how to find out if a page's menu-item is a parent of other menu-items, or does it? –  Nick Dec 12 '10 at 9:29
    
Sorry. I assumed you'd know that you need to query the db using $wpdb to know that. –  Denis Dec 12 '10 at 11:04
add comment

You could use some jQuery, i'd have thought a couple of lines of script is lighter then having to do lookup queries to figure out which items have children..

<script type="text/javascript">  
jQuery(document).ready( function($) {
    $('#my_menu_id li.current-menu-item').has('ul').addClass('has_children');
});
</script>

Of course making sure to update the selector to match your menu ID(s)/Class(es)...

Reference for jQuery has function. http://api.jquery.com/has/

share|improve this answer
    
That is probably easier than trying to run the check at the body_class filter, but I think he wanted to add the has_children tag to the body class, not to the menu item. Just a minor change. –  goldenapples Dec 12 '10 at 18:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.