#27616 closed enhancement (duplicate)
Add first-menu-item and last-menu-item classes
Reported by: | core_2_duo | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | trivial | Version: | 3.8.1 |
Component: | Menus | Keywords: | 2nd-opinion close |
Focuses: | Cc: |
Description
Add first-menu-item and last-menu-item classes to nav menus items, including all child menus. It's may be useful for CSS when you have to build site with IE6-7 support, because you often need to set borders or colors of the first or of the last elements.
Pull request & code are here: https://github.com/WordPress/WordPress/pull/78
Attachments (1)
Change History (6)
#1
follow-up:
↓ 2
@
11 years ago
- Keywords 2nd-opinion added
If you really want to support IE6-7 use this filter instead nav_menu_css_class :)
#2
in reply to:
↑ 1
@
11 years ago
Replying to fgirardey:
If you really want to support IE6-7 use this filter instead nav_menu_css_class :)
I use this filter now
function add_first_and_last($items) { $parents = array(); foreach ($items as $key => $item) { if (! array_key_exists($item->menu_item_parent, $parents)) { $item->classes []= 'first-menu-item'; } else { array_pop($items[$parents[$item->menu_item_parent]]->classes); } $parents[$item->menu_item_parent] = $key; $item->classes []= 'last-menu-item'; } return $items; } add_filter('wp_nav_menu_objects', 'add_first_and_last');
It is similar to code, that I've added in nav-menu-template.php.
But I guess, you are right. It's kinda specific feature and it can be solved through filters, when you need it.
Note: See
TracTickets for help on using
tickets.
Updated nav-menu-template.php