Make WordPress Core

Changeset 25602


Ignore:
Timestamp:
09/24/2013 04:00:14 PM (11 years ago)
Author:
helen
Message:

Add classes to menus to indicate that an item has sub-items: .menu-item-has-children for wp_nav_menu() and .page_item_has_children for wp_page_menu(). props hotchkissconsulting. fixes #23834.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/nav-menu-template.php

    r25410 r25602  
    272272    _wp_menu_item_classes_by_context( $menu_items );
    273273
    274     $sorted_menu_items = array();
    275     foreach ( (array) $menu_items as $key => $menu_item )
    276         $sorted_menu_items[$menu_item->menu_order] = $menu_item;
    277 
    278     unset($menu_items);
     274    $sorted_menu_items = $menu_items_with_children = array();
     275    foreach ( (array) $menu_items as $menu_item ) {
     276        $sorted_menu_items[ $menu_item->menu_order ] = $menu_item;
     277        if ( $menu_item->menu_item_parent )
     278            $menu_items_with_children[ $menu_item->menu_item_parent ] = true;
     279    }
     280
     281    // Add the menu-item-has-children class where applicable
     282    if ( $menu_items_with_children ) {
     283        foreach ( $sorted_menu_items as &$menu_item ) {
     284            if ( isset( $menu_items_with_children[ $menu_item->ID ] ) )
     285                $menu_item->classes[] = 'menu-item-has-children';
     286        }
     287    }
     288
     289    unset( $menu_items, $menu_item );
    279290
    280291    /**
  • trunk/src/wp-includes/post-template.php

    r25582 r25602  
    956956        $walker = $r['walker'];
    957957
     958    foreach ( (array) $pages as $page ) {
     959        if ( $page->post_parent )
     960            $r['pages_with_children'][ $page->post_parent ] = true;
     961    }
     962
    958963    $args = array($pages, $depth, $r, $current_page);
    959964    return call_user_func_array(array($walker, 'walk'), $args);
     
    10441049        extract($args, EXTR_SKIP);
    10451050        $css_class = array('page_item', 'page-item-'.$page->ID);
     1051
     1052        if( isset( $args['pages_with_children'][ $page->ID ] ) )
     1053            $css_class[] = 'page_item_has_children';
     1054
    10461055        if ( !empty($current_page) ) {
    10471056            $_current_page = get_post( $current_page );
Note: See TracChangeset for help on using the changeset viewer.