Ticket #34839: 34839.diff
File 34839.diff, 3.8 KB (added by , 8 years ago) |
---|
-
wp-includes/nav-menu-template.php
361 361 ) { 362 362 $classes[] = 'current-menu-item'; 363 363 $menu_items[$key]->current = true; 364 $_anc_id = (int) $menu_item->db_id;365 364 366 while(367 ( $_anc_id = get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) ) &&368 ! in_array( $_anc_id, $active_ancestor_item_ids )369 ) {370 $active_ancestor_item_ids[] = $_anc_id;371 }372 373 365 if ( 'post_type' == $menu_item->type && 'page' == $menu_item->object ) { 374 366 // Back compat classes for pages to match wp_page_menu() 375 367 $classes[] = 'page_item'; … … 376 368 $classes[] = 'page-item-' . $menu_item->object_id; 377 369 $classes[] = 'current_page_item'; 378 370 } 379 $active_parent_item_ids[] = (int) $menu_item->menu_item_parent;380 $active_parent_object_ids[] = (int) $menu_item->post_parent;381 $active_object = $menu_item->object;382 371 383 372 // if the menu item corresponds to the currently-queried post type archive 384 373 } elseif ( … … 387 376 ) { 388 377 $classes[] = 'current-menu-item'; 389 378 $menu_items[$key]->current = true; 379 390 380 // if the menu item corresponds to the currently-requested URL 391 381 } elseif ( 'custom' == $menu_item->object && isset( $_SERVER['HTTP_HOST'] ) ) { 392 382 $_root_relative_current = untrailingslashit( $_SERVER['REQUEST_URI'] ); … … 398 388 if ( $raw_item_url && in_array( $item_url, array( $current_url, $_indexless_current, $_root_relative_current ) ) ) { 399 389 $classes[] = 'current-menu-item'; 400 390 $menu_items[$key]->current = true; 401 $_anc_id = (int) $menu_item->db_id;402 391 403 while(404 ( $_anc_id = get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) ) &&405 ! in_array( $_anc_id, $active_ancestor_item_ids )406 ) {407 $active_ancestor_item_ids[] = $_anc_id;408 }409 410 392 if ( in_array( home_url(), array( untrailingslashit( $current_url ), untrailingslashit( $_indexless_current ) ) ) ) { 411 393 // Back compat for home link to match wp_page_menu() 412 394 $classes[] = 'current_page_item'; 413 395 } 414 $active_parent_item_ids[] = (int) $menu_item->menu_item_parent;415 $active_parent_object_ids[] = (int) $menu_item->post_parent;416 $active_object = $menu_item->object;417 396 418 397 // give front page item current-menu-item class when extra query arguments involved 419 398 } elseif ( $item_url == $front_page_url && is_front_page() ) { … … 424 403 $classes[] = 'menu-item-home'; 425 404 } 426 405 406 // if current item, set active menu parent and ancestors 407 if ( $menu_items[$key]->current ) { 408 $active_parent_item_ids[] = (int) $menu_item->menu_item_parent; 409 $active_parent_object_ids[] = (int) $menu_item->post_parent; 410 $active_object = $menu_item->object; 411 412 $_anc_id = (int) $menu_item->menu_item_parent; 413 while( 414 ! in_array( $_anc_id, $active_ancestor_item_ids ) 415 ) { 416 $active_ancestor_item_ids[] = $_anc_id; 417 foreach ( (array) $menu_items as $_key => $_parent ) { 418 if ( $_parent->db_id == $_anc_id ) { 419 $_anc_id = $_parent->menu_item_parent; 420 break; 421 } 422 } 423 } 424 } 425 427 426 // back-compat with wp_page_menu: add "current_page_parent" to static home page link for any non-page query 428 427 if ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && empty( $wp_query->is_page ) && $home_page_id == $menu_item->object_id ) 429 428 $classes[] = 'current_page_parent'; … … 430 429 431 430 $menu_items[$key]->classes = array_unique( $classes ); 432 431 } 432 433 433 $active_ancestor_item_ids = array_filter( array_unique( $active_ancestor_item_ids ) ); 434 434 $active_parent_item_ids = array_filter( array_unique( $active_parent_item_ids ) ); 435 435 $active_parent_object_ids = array_filter( array_unique( $active_parent_object_ids ) );