[wp-trac] [WordPress Trac] #27616: Add first-menu-item and last-menu-item classes

WordPress Trac noreply at wordpress.org
Tue Apr 1 08:50:33 UTC 2014


#27616: Add first-menu-item and last-menu-item classes
-------------------------+------------------------------
 Reporter:  core_2_duo   |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Menus        |     Version:  3.8.1
 Severity:  normal       |  Resolution:
 Keywords:  2nd-opinion  |     Focuses:
-------------------------+------------------------------

Comment (by core_2_duo):

 Replying to [comment:1 fgirardey]:
 > If you really want to support IE6-7 use this filter instead
 [http://codex.wordpress.org/Plugin_API/Filter_Reference/nav_menu_css_class
 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.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/27616#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list