Make WordPress Core

Opened 15 years ago

Closed 14 years ago

Last modified 11 years ago

#14250 closed feature request (wontfix)

wp_nav_menu separator and first last class

Reported by: spathon's profile 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 @hakre
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 @trilibi
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.

#4 @fjarrett
14 years ago

@trilibi - excellent! thank you very much :)

#5 @nacin
14 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

#6 @hm2k
13 years ago

adding first/last classes is a duplicate of #9011.

#7 @helen
11 years ago

#27616 was marked as a duplicate.

Note: See TracTickets for help on using tickets.