Changeset 15105
- Timestamp:
- 06/02/2010 01:48:26 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/nav-menu-template.php
r15077 r15105 69 69 $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; 70 70 71 $classes = $value = ''; 72 73 $classes = array( 'menu-item', 'menu-item-type-' . $item->type ); 74 if ( !empty($item->classes) ) 75 $classes = array_merge( $classes, $item->classes ); 76 77 if ( 'custom' != $item->type ) { 78 $classes[] = 'menu-item-object-' . $item->object; 79 $classes[] = 'menu-item-object-' . $item->type . '-' . $item->object_id; 80 if ( 'post_type' == $item->type && 'page' == $item->object ) { 81 // Back compat classes for pages to match wp_page_menu() 82 $classes[] = 'page_item'; 83 $classes[] = 'page-item-' . $item->object_id; 84 if ( ! empty( $item->classes ) ) { 85 if ( in_array('current-menu-item', $classes) ) 86 $classes[] = 'current_page_item'; 87 if ( in_array('current-menu-parent', $classes) ) 88 $classes[] = 'current_page_parent'; 89 if ( in_array('current-menu-ancestor', $classes) ) 90 $classes[] = 'current_page_ancestor'; 91 } 92 } 93 } elseif ( 'custom' == $item->type && in_array('current-menu-item', $classes) && in_array('menu-item-home', $classes) ) { 94 // Back compat for home limk to match wp_page_menu() 95 $classes[] = 'current_page_item'; 96 } 97 98 $classes = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) ); 99 $classes = ' class="' . esc_attr( $classes ) . '"'; 100 101 $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $classes .'>'; 71 $class_names = $value = ''; 72 73 $classes = empty( $item->classes ) ? array() : (array) $item->classes; 74 75 $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) ); 76 $class_names = ' class="' . esc_attr( $class_names ) . '"'; 77 78 $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>'; 102 79 103 80 $attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : ''; … … 287 264 288 265 foreach ( (array) $menu_items as $key => $menu_item ) { 266 $classes = (array) $menu_item->classes; 267 $classes[] = 'menu-item'; 268 $classes[] = 'menu-item-type-' . $menu_item->type; 269 289 270 // if the menu item corresponds to a taxonomy term for the currently-queried non-hierarchical post object 290 271 if ( $wp_query->is_singular && 'taxonomy' == $menu_item->type && in_array( $menu_item->object_id, $possible_object_parents ) ) { … … 302 283 ) 303 284 ) { 304 $menu_items[$key]->classes[] = 'current-menu-item'; 285 $classes[] = 'current-menu-item'; 286 if ( 'post_type' == $menu_item->type && 'page' == $menu_item->object ) { 287 // Back compat classes for pages to match wp_page_menu() 288 $classes[] = 'page_item'; 289 $classes[] = 'page-item-' . $menu_item->object_id; 290 $classes[] = 'current_page_item'; 291 } 305 292 $active_parent_item_ids[] = (int) $menu_item->menu_item_parent; 306 293 $active_parent_object_ids[] = (int) $menu_item->post_parent; … … 312 299 $item_url = strpos( $menu_item->url, '#' ) ? substr( $menu_item->url, 0, strpos( $menu_item->url, '#' ) ) : $menu_item->url; 313 300 if ( $item_url == $current_url ) { 314 $menu_items[$key]->classes[] = 'current-menu-item'; 315 if ( untrailingslashit($current_url) == home_url() ) 316 $menu_items[$key]->classes[] = 'menu-item-home'; 301 $classes[] = 'current-menu-item'; 302 if ( untrailingslashit($current_url) == home_url() ) { 303 $classes[] = 'menu-item-home'; 304 // Back compat for home limk to match wp_page_menu() 305 $classes[] = 'current_page_item'; 306 } 317 307 $active_parent_item_ids[] = (int) $menu_item->menu_item_parent; 318 308 $active_parent_object_ids[] = (int) $menu_item->post_parent; … … 323 313 // back-compat with wp_page_menu: add "current_page_parent" to static home page link for any non-page query 324 314 if ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && empty( $wp_query->is_page ) && $home_page_id == $menu_item->object_id ) 325 $menu_items[$key]->classes[] = 'current_page_parent'; 315 $classes[] = 'current_page_parent'; 316 317 $menu_items[$key]->classes = array_unique( $classes ); 326 318 } 327 319 … … 331 323 // set parent's class 332 324 foreach ( (array) $menu_items as $key => $parent_item ) { 325 $classes = (array) $parent_item->classes; 326 333 327 if ( 334 328 isset( $parent_item->type ) && … … 337 331 is_post_type_hierarchical( $queried_object->post_type ) && 338 332 in_array( $parent_item->object_id, $queried_object->ancestors ) 339 ) 340 $menu_items[$key]->classes[] = 'current-' . $queried_object->post_type . '-ancestor current-menu-ancestor'; 333 ) { 334 $classes[] = 'current-' . $queried_object->post_type . '-ancestor'; 335 $classes[] = 'current-menu-ancestor'; 336 } 341 337 if ( in_array( $parent_item->db_id, $active_parent_item_ids ) ) 342 $ menu_items[$key]->classes[] = 'current-menu-parent';338 $classes[] = 'current-menu-parent'; 343 339 if ( in_array( $parent_item->object_id, $active_parent_object_ids ) ) 344 $menu_items[$key]->classes[] = 'current-' . $active_object . '-parent'; 340 $classes[] = 'current-' . $active_object . '-parent'; 341 342 if ( 'post_type' == $parent_item->type && 'page' == $parent_item->object ) { 343 // Back compat classes for pages to match wp_page_menu() 344 if ( in_array('current-menu-parent', $classes) ) 345 $classes[] = 'current_page_parent'; 346 if ( in_array('current-menu-ancestor', $classes) ) 347 $classes[] = 'current_page_ancestor'; 348 } 349 350 $menu_items[$key]->classes = array_unique( $classes ); 345 351 } 346 352 }
Note: See TracChangeset
for help on using the changeset viewer.