[wp-trac] [WordPress Trac] #20347: Extra menu classes ( First, Last )
WordPress Trac
wp-trac at lists.automattic.com
Tue Apr 3 08:37:55 UTC 2012
#20347: Extra menu classes ( First, Last )
-----------------------------+---------------------------------
Reporter: veke | Owner: vekexasia@…
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Menus | Version: 3.3.1
Severity: minor | Keywords: has-patch
-----------------------------+---------------------------------
It would be nice to add, only to the first and the last item, an extra
class to the current ( very useful ) list of menu classes.
Ex: if the menu is composed as following:
# Home
# Second Page
# Third Page
# Last page.
than :
{{{
Home will also have the class $menuClass-first
Last page will also have the class $menuClass-last
}}}
So far i solved this "issue" hooking to the filter wp_nav_menu_objects
with the following code:
{{{
static function addUsefulClassesToMenusElements($sorted_menu_items, $args)
{
$count = 0;
$menuClass = $args->menu_class;
foreach ($sorted_menu_items as $k=>$item) {
if ($count == 0) {
$item->classes[] = $menuClass.'-first';
}
if ($count == count($sorted_menu_items)-1) {
$item->classes[] = $menuClass.'-last';
}
$count++;
}
return $sorted_menu_items;
}
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/20347>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list