Changeset 33764
- Timestamp:
- 08/26/2015 07:41:55 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/category-template.php
r33763 r33764 462 462 * 463 463 * @since 2.1.0 464 * @since 4.4.0 Introduced the `hide_title_if_no_cats` argument. 464 465 * 465 466 * @param string|array $args { … … 492 493 * @type string $title_li Text to use for the list title `<li>` element. Pass an empty string 493 494 * to disable. Default 'Categories'. 495 * @type bool $hide_title_if_no_cats Whether to hide the `$title_li` element if there are no terms in 496 * the list. Default false (title will always be shown). 494 497 * @type int $depth Category depth. Used for tab indentation. Default 0. 495 498 * @type string $taxonomy Taxonomy name. Default 'category'. … … 508 511 'exclude_tree' => '', 'current_category' => 0, 509 512 'hierarchical' => true, 'title_li' => __( 'Categories' ), 513 'hide_title_if_no_cats' => false, 510 514 'echo' => 1, 'depth' => 0, 511 515 'taxonomy' => 'category' … … 535 539 536 540 $output = ''; 537 if ( $r['title_li'] && 'list' == $r['style'] ) {541 if ( $r['title_li'] && 'list' == $r['style'] && ( ! empty( $categories ) || ! $r['hide_title_if_no_cats'] ) ) { 538 542 $output = '<li class="' . esc_attr( $r['class'] ) . '">' . $r['title_li'] . '<ul>'; 539 543 } -
trunk/tests/phpunit/tests/category/wpListCategories.php
r32292 r33764 198 198 return $cat; 199 199 } 200 201 /** 202 * @ticket 33460 203 */ 204 public function test_title_li_should_be_shown_by_default_for_empty_lists() { 205 $found = wp_list_categories( array( 206 'echo' => false, 207 ) ); 208 209 $this->assertContains( '<li class="categories">Categories', $found ); 210 } 211 212 /** 213 * @ticket 33460 214 */ 215 public function test_hide_title_if_no_cats_should_be_respected_for_empty_lists_when_true() { 216 $found = wp_list_categories( array( 217 'echo' => false, 218 'hide_title_if_no_cats' => true, 219 ) ); 220 221 $this->assertNotContains( '<li class="categories">Categories', $found ); 222 } 223 224 /** 225 * @ticket 33460 226 */ 227 public function test_hide_title_if_no_cats_should_be_respected_for_empty_lists_when_false() { 228 $found = wp_list_categories( array( 229 'echo' => false, 230 'hide_title_if_no_cats' => false, 231 ) ); 232 233 $this->assertContains( '<li class="categories">Categories', $found ); 234 } 235 236 /** 237 * @ticket 33460 238 */ 239 public function test_hide_title_if_no_cats_should_be_ignored_when_category_list_is_not_empty() { 240 $cat = $this->factory->category->create(); 241 242 $found = wp_list_categories( array( 243 'echo' => false, 244 'hide_empty' => false, 245 'hide_title_if_no_cats' => true, 246 ) ); 247 248 $this->assertContains( '<li class="categories">Categories', $found ); 249 } 200 250 }
Note: See TracChangeset
for help on using the changeset viewer.