#14250 closed feature request (wontfix)
wp_nav_menu separator and first last class
Reported by: | spathon | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | General | Keywords: | wp_nav_menu |
Focuses: | Cc: |
Description
In some of the wp sites I do there is a separator between the menu items and I think it would be good if there were some argument to add separators to the wp_nav_menu($args).
Like now you can use link_before or link_after but you don't want the last or first to have it.
Example:
Start | About | Contact
And it would be good if there were a first and last class on the items
Example:
.menu-item-first .menu-item-last
Change History (7)
#2
@
14 years ago
I think adding "first" and "last" is enough when it's added additionally. I've implemented something like that for widgets: #12615
I do not see any first and last selectors in css2:
http://www.w3.org/TR/CSS2/selector.html
even, odd and nth child:
http://www.w3.org/Style/Examples/007/evenodd
CSS3 pseudo classes:
http://www.w3.org/TR/css3-selectors/#pseudo-classes
I have no idea which browser do really support that, so it might just be useful to have some classes for older browsers.
#3
@
14 years ago
Here is a little filter I use to help with first and last.
function nav_menu_first_last( $items ) { $position = strrpos($items, 'class="menu-item', -1); $items=substr_replace($items, 'menu-item-last ', $position+7, 0); $position = strpos($items, 'class="menu-item'); $items=substr_replace($items, 'menu-item-first ', $position+7, 0); return $items; } add_filter( 'wp_nav_menu_items', 'nav_menu_first_last' );
@hakre - You are correct on the lack of support for the first/last pseudo selectors. Probably less then half of the browsers out there support it.
-1 on .menu-item-first .menu-item-last. See http://lists.automattic.com/pipermail/wp-hackers/2010-July/032849.html