Make WordPress Core

Opened 4 years ago

Closed 18 months ago

#15214 closed enhancement (duplicate)

Add class for menu items containing a sub-menu

Reported by: chrisjean Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.1
Component: Menus Keywords: has-patch 3.4-early
Focuses: Cc:


I wanted to add a class to the menu item LI elements for navigation menus that have sub menus. This would allow me to do some specific styling such as using a background that shows that a sub menu is available on hover.

I found that adding this support for both the wp_nav_menu and wp_list_pages functions was quite simple. So, I put together a patch in case it might be a good candidate for core.

The new classes are menu-item-with-sub-menu and page_item_with_children for wp_nav_menu and wp_list_pages, respectively. These class names were chosen to closely match the existing navigation classes of menu-item, sub-menu, page_item, and children.

I should note that while making this modification I found that the display_element method of the Walker class doesn't set has_children when $args is an object, just when it is an array. The patch also handles fixing this shortcoming of the Walker API.

Attachments (3)

add-parent-menu-item-class.diff (1.5 KB) - added by chrisbliss18 4 years ago.
class-wp-walker.php.patch (591 bytes) - added by bjornjohansen 3 years ago.
Updated patch
15214.diff (2.2 KB) - added by obenland 2 years ago.

Download all attachments as: .zip

Change History (14)

comment:2 @nacin4 years ago

  • Milestone changed from Awaiting Review to Future Release

comment:3 @mikeschinkel4 years ago

  • Cc mikeschinkel@… added

comment:4 @ocean903 years ago

  • Keywords 3.4-early added

comment:5 @kwight3 years ago

  • Cc kwight@… added

comment:6 @bjornjohansen3 years ago

Current version is 3.4.1 and this still isn't in trunk. What's the status on this one?

The file classes.php doesn't exist anymore, so the patch is now outdated.

The Walker class is now in class-wp-walker.php, but still need the two-line-update to accomodate for when $args is an object.

The changes in both the Walker_Page class (now in post-template.php) and nav-menu-template.php can now be done with a filter (wasn't possible at the time the ticket was opened).

@bjornjohansen3 years ago

Updated patch

comment:7 @SergeyBiryukov3 years ago

Related/duplicate: #21534

@obenland2 years ago

comment:9 @obenland2 years ago

Refreshed patch.

comment:10 @SergeyBiryukov23 months ago

Let's add the fix for the Walker class in #21534 and then use this ticket to add the classes.

comment:11 @helen18 months ago

  • Milestone Future Release deleted
  • Resolution set to duplicate
  • Status changed from new to closed

#23834 has more current patches; these turned out to be the same end result.

Note: See TracTickets for help on using tickets.