Ticket #13831: term-ancestor-classes.13831.diff
File term-ancestor-classes.13831.diff, 3.8 KB (added by , 14 years ago) |
---|
-
wp-includes/nav-menu-template.php
250 250 $active_object = ''; 251 251 $active_parent_item_ids = array(); 252 252 $active_parent_object_ids = array(); 253 $possible_taxonomy_ancestors = array(); 253 254 $possible_object_parents = array(); 254 255 $home_page_id = (int) get_option( 'page_for_posts' ); 255 256 256 257 if ( $wp_query->is_singular && ! empty( $queried_object->post_type ) && ! is_post_type_hierarchical( $queried_object->post_type ) ) { 257 258 foreach ( (array) get_object_taxonomies( $queried_object->post_type ) as $taxonomy ) { 258 259 if ( is_taxonomy_hierarchical( $taxonomy ) ) { 260 $term_hierarchy = _get_term_hierarchy( $taxonomy ); 259 261 $terms = wp_get_object_terms( $queried_object_id, $taxonomy, array( 'fields' => 'ids' ) ); 260 if ( is_array( $terms ) ) 262 if ( is_array( $terms ) ) { 261 263 $possible_object_parents = array_merge( $possible_object_parents, $terms ); 264 $term_to_ancestor = array(); 265 foreach ( (array) $term_hierarchy as $anc => $descs ) { 266 foreach ( (array) $descs as $desc ) 267 $term_to_ancestor[ $desc ] = $anc; 268 } 269 270 foreach ( $terms as $desc ) { 271 do { 272 $possible_taxonomy_ancestors[ $taxonomy ][] = $desc; 273 if ( isset( $term_to_ancestor[ $desc ] ) ) { 274 $_desc = $term_to_ancestor[ $desc ]; 275 unset( $term_to_ancestor[ $desc ] ); 276 $desc = $_desc; 277 } else { 278 $desc = 0; 279 } 280 } while ( ! empty( $desc ) ); 281 } 282 } 262 283 } 263 284 } 264 285 } elseif ( ! empty( $queried_object->post_type ) && is_post_type_hierarchical( $queried_object->post_type ) ) { 265 286 _get_post_ancestors( $queried_object ); 287 } elseif ( ! empty( $queried_object->taxonomy ) && is_taxonomy_hierarchical( $queried_object->taxonomy ) ) { 288 $term_hierarchy = _get_term_hierarchy( $queried_object->taxonomy ); 289 $term_to_ancestor = array(); 290 foreach ( (array) $term_hierarchy as $anc => $descs ) { 291 foreach ( (array) $descs as $desc ) 292 $term_to_ancestor[ $desc ] = $anc; 293 } 294 $desc = $queried_object->term_id; 295 do { 296 $possible_taxonomy_ancestors[ $queried_object->taxonomy ][] = $desc; 297 if ( isset( $term_to_ancestor[ $desc ] ) ) { 298 $_desc = $term_to_ancestor[ $desc ]; 299 unset( $term_to_ancestor[ $desc ] ); 300 $desc = $_desc; 301 } else { 302 $desc = 0; 303 } 304 } while ( ! empty( $desc ) ); 266 305 } 267 306 268 307 $possible_object_parents = array_filter( $possible_object_parents ); … … 331 370 332 371 if ( 333 372 isset( $parent_item->type ) && 334 'post_type' == $parent_item->type && 335 ! empty( $queried_object->post_type ) && 336 is_post_type_hierarchical( $queried_object->post_type ) && 337 in_array( $parent_item->object_id, $queried_object->ancestors ) 373 ( 374 // ancestral post object 375 ( 376 'post_type' == $parent_item->type && 377 ! empty( $queried_object->post_type ) && 378 is_post_type_hierarchical( $queried_object->post_type ) && 379 in_array( $parent_item->object_id, $queried_object->ancestors ) 380 ) || 381 382 // ancestral term 383 ( 384 'taxonomy' == $parent_item->type && 385 isset( $possible_taxonomy_ancestors[ $parent_item->object ] ) && 386 in_array( $parent_item->object_id, $possible_taxonomy_ancestors[ $parent_item->object ] ) 387 ) 388 ) 338 389 ) { 339 $classes[] = 'current-' . $queried_object->post_type. '-ancestor';390 $classes[] = empty( $queried_object->taxonomy ) ? 'current-' . $queried_object->post_type . '-ancestor' : 'current-' . $queried_object->taxonomy . '-ancestor'; 340 391 $classes[] = 'current-menu-ancestor'; 341 392 } 393 342 394 if ( in_array( $parent_item->db_id, $active_parent_item_ids ) ) 343 395 $classes[] = 'current-menu-parent'; 344 396 if ( in_array( $parent_item->object_id, $active_parent_object_ids ) )