Changeset 33804
- Timestamp:
- 08/29/2015 07:45:35 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/category-template.php
r33767 r33804 462 462 * 463 463 * @since 2.1.0 464 * @since 4.4.0 Introduced the `hide_title_if_empty` argument. 464 * @since 4.4.0 Introduced the `hide_title_if_empty` argument. The `current_category` argument was modified to 465 * optionally accept an array of values. 465 466 * 466 467 * @param string|array $args { … … 489 490 * with their descendants. See {@link get_terms()}. Default empty string. 490 491 * @type bool|int $echo True to echo markup, false to return it. Default 1. 491 * @type int $current_category Category that should get the 'current-cat' class. Default 0. 492 * @type int|array $current_category ID of category, or array of IDs of categories, that should get the 493 * 'current-cat' class. Default 0. 492 494 * @type bool $hierarchical Whether to include terms that have non-empty descendants. 493 495 * See {@link get_terms()}. Default true. … … 1122 1124 1123 1125 if ( ! empty( $args['current_category'] ) ) { 1124 $_current_category = get_term( $args['current_category'], $category->taxonomy ); 1125 if ( $category->term_id == $args['current_category'] ) { 1126 $css_classes[] = 'current-cat'; 1127 } elseif ( $category->term_id == $_current_category->parent ) { 1128 $css_classes[] = 'current-cat-parent'; 1126 // 'current_category' can be an array, so we use `get_terms()`. 1127 $_current_terms = get_terms( $category->taxonomy, array( 1128 'include' => $args['current_category'], 1129 'hide_empty' => false, 1130 ) ); 1131 1132 foreach ( $_current_terms as $_current_term ) { 1133 if ( $category->term_id == $_current_term->term_id ) { 1134 $css_classes[] = 'current-cat'; 1135 } elseif ( $category->term_id == $_current_term->parent ) { 1136 $css_classes[] = 'current-cat-parent'; 1137 } 1129 1138 } 1130 1139 } -
trunk/tests/phpunit/tests/category/wpListCategories.php
r33767 r33804 47 47 48 48 /** 49 * @ticket 33565 50 */ 51 public function test_current_category_should_accept_an_array_of_ids() { 52 $cats = $this->factory->category->create_many( 3 ); 53 54 $found = wp_list_categories( array( 55 'echo' => false, 56 'hide_empty' => false, 57 'current_category' => array( $cats[0], $cats[2] ), 58 ) ); 59 60 $this->assertRegExp( '/class="[^"]*cat-item-' . $cats[0] . '[^"]*current-cat[^"]*"/', $found ); 61 $this->assertNotRegExp( '/class="[^"]*cat-item-' . $cats[1] . '[^"]*current[^"]*"/', $found ); 62 $this->assertRegExp( '/class="[^"]*cat-item-' . $cats[2] . '[^"]*current-cat[^"]*"/', $found ); 63 } 64 65 /** 49 66 * @ticket 16792 50 67 */
Note: See TracChangeset
for help on using the changeset viewer.