WordPress.org

Make WordPress Core

Ticket #12812: add-ancestor-classes.12812.diff

File add-ancestor-classes.12812.diff, 1.9 KB (added by filosofo, 11 years ago)
  • wp-includes/nav-menu-template.php

     
    292292                                        $possible_object_parents = array_merge( $possible_object_parents, $terms );
    293293                        }
    294294                }
     295        } elseif ( ! empty( $queried_object->post_type ) && is_post_type_hierarchical( $queried_object->post_type ) ) {
     296                _get_post_ancestors( $queried_object );
    295297        }
    296298
    297299        $possible_object_parents = array_filter( $possible_object_parents );
     
    333335        $active_parent_object_ids = array_filter( array_unique( $active_parent_object_ids ) );
    334336
    335337        // set parent's class
    336         if ( ! empty( $active_parent_item_ids ) || ! empty( $active_parent_object_ids ) ) {
    337                 foreach( (array) $menu_items as $key => $parent_item ) {
    338                         if ( in_array( $parent_item->db_id, $active_parent_item_ids ) )
    339                                 $menu_items[$key]->classes = trim( $parent_item->classes . ' ' . 'current-menu-parent' );
    340                         if ( in_array( $parent_item->object_id, $active_parent_object_ids ) )
    341                                 $menu_items[$key]->classes = trim( $parent_item->classes . ' ' . 'current-' . $active_object . '-parent' );
    342                 }
     338        foreach( (array) $menu_items as $key => $parent_item ) {
     339                if ( 'post_type' == $parent_item->type && is_post_type_hierarchical( $queried_object->post_type ) && in_array( $parent_item->object_id, $queried_object->ancestors ) )
     340                        $menu_items[$key]->classes = trim( $parent_item->classes . ' ' . 'current-' . $queried_object->post_type . '-ancestor' );
     341                if ( in_array( $parent_item->db_id, $active_parent_item_ids ) )
     342                        $menu_items[$key]->classes = trim( $parent_item->classes . ' ' . 'current-menu-parent' );
     343                if ( in_array( $parent_item->object_id, $active_parent_object_ids ) )
     344                        $menu_items[$key]->classes = trim( $parent_item->classes . ' ' . 'current-' . $active_object . '-parent' );
    343345        }
    344346}
    345347