Make WordPress Core


Ignore:
Timestamp:
08/26/2015 07:41:55 PM (8 years ago)
Author:
boonebgorges
Message:

Introduce hide_title_if_no_cats parameter to wp_list_categories().

When generating a <ul> using wp_list_categories(), a title <li> element
is put at the top of the term list. Current behavior is that this title <li>
appears even when no terms are found. The new hide_title_if_no_cats param
allows developers to specify that the title should be hidden when the term list
is empty.

Props vilkatis.
Fixes #33460.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/category/wpListCategories.php

    r32292 r33764  
    198198        return $cat;
    199199    }
     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    }
    200250}
Note: See TracChangeset for help on using the changeset viewer.