diff --git a/src/wp-includes/nav-menu-template.php b/src/wp-includes/nav-menu-template.php index ffa9918367..52a6e0f64b 100644 --- a/src/wp-includes/nav-menu-template.php +++ b/src/wp-includes/nav-menu-template.php @@ -271,11 +271,22 @@ function wp_nav_menu( $args = array() ) { // Set up the $menu_item variables _wp_menu_item_classes_by_context( $menu_items ); - $sorted_menu_items = array(); - foreach ( (array) $menu_items as $key => $menu_item ) - $sorted_menu_items[$menu_item->menu_order] = $menu_item; + $sorted_menu_items = $menu_items_with_children = array(); + foreach ( (array) $menu_items as $menu_item ) { + $sorted_menu_items[ $menu_item->menu_order ] = $menu_item; + if ( $menu_item->menu_item_parent ) + $menu_items_with_children[ $menu_item->menu_item_parent ] = true; + } - unset($menu_items); + // Add the menu-item-has-children class where applicable + if ( $menu_items_with_children ) { + foreach ( $sorted_menu_items as &$menu_item ) { + if ( isset( $menu_items_with_children[ $menu_item->ID ] ) ) + $menu_item->classes[] = 'menu-item-has-children'; + } + } + + unset( $menu_items, $menu_item ); /** * Filter the sorted list of menu item objects before generating the menu's HTML. diff --git a/src/wp-includes/post-template.php b/src/wp-includes/post-template.php index 16e946aef1..c6b73e0d53 100644 --- a/src/wp-includes/post-template.php +++ b/src/wp-includes/post-template.php @@ -955,6 +955,11 @@ function walk_page_tree($pages, $depth, $current_page, $r) { else $walker = $r['walker']; + foreach ( (array) $pages as $page ) { + if ( $page->post_parent ) + $r['pages_with_children'][ $page->post_parent ] = true; + } + $args = array($pages, $depth, $r, $current_page); return call_user_func_array(array($walker, 'walk'), $args); } @@ -1043,6 +1048,10 @@ class Walker_Page extends Walker { extract($args, EXTR_SKIP); $css_class = array('page_item', 'page-item-'.$page->ID); + + if( isset( $args['pages_with_children'][ $page->ID ] ) ) + $css_class[] = 'page_item_has_children'; + if ( !empty($current_page) ) { $_current_page = get_post( $current_page ); if ( in_array( $page->ID, $_current_page->ancestors ) )