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/src/wp-includes/category-template.php

    r33763 r33764  
    462462 *
    463463 * @since 2.1.0
     464 * @since 4.4.0 Introduced the `hide_title_if_no_cats` argument.
    464465 *
    465466 * @param string|array $args {
     
    492493 *     @type string       $title_li           Text to use for the list title `<li>` element. Pass an empty string
    493494 *                                            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).
    494497 *     @type int          $depth              Category depth. Used for tab indentation. Default 0.
    495498 *     @type string       $taxonomy           Taxonomy name. Default 'category'.
     
    508511        'exclude_tree' => '', 'current_category' => 0,
    509512        'hierarchical' => true, 'title_li' => __( 'Categories' ),
     513        'hide_title_if_no_cats' => false,
    510514        'echo' => 1, 'depth' => 0,
    511515        'taxonomy' => 'category'
     
    535539
    536540    $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'] ) ) {
    538542        $output = '<li class="' . esc_attr( $r['class'] ) . '">' . $r['title_li'] . '<ul>';
    539543    }
Note: See TracChangeset for help on using the changeset viewer.