Make WordPress Core


Ignore:
Timestamp:
03/28/2010 02:07:31 AM (15 years ago)
Author:
dd32
Message:

Update wp_list_categories() to be custom taxonomy aware. Props jfarthing84. See #11838

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/category-template.php

    r13813 r13854  
    449449function wp_list_categories( $args = '' ) {
    450450    $defaults = array(
    451         'show_option_all' => '', 'orderby' => 'name',
    452         'order' => 'ASC', 'show_last_update' => 0,
    453         'style' => 'list', 'show_count' => 0,
    454         'hide_empty' => 1, 'use_desc_for_title' => 1,
    455         'child_of' => 0, 'feed' => '', 'feed_type' => '',
    456         'feed_image' => '', 'exclude' => '', 'exclude_tree' => '', 'current_category' => 0,
     451        'show_option_all' => '', 'show_option_none' => __('No categories'),
     452        'orderby' => 'name', 'order' => 'ASC',
     453        'show_last_update' => 0, 'style' => 'list',
     454        'show_count' => 0, 'hide_empty' => 1,
     455        'use_desc_for_title' => 1, 'child_of' => 0,
     456        'feed' => '', 'feed_type' => '',
     457        'feed_image' => '', 'exclude' => '',
     458        'exclude_tree' => '', 'current_category' => 0,
    457459        'hierarchical' => true, 'title_li' => __( 'Categories' ),
    458         'echo' => 1, 'depth' => 0
     460        'echo' => 1, 'depth' => 0,
     461        'taxonomy' => 'category'
    459462    );
    460463
    461464    $r = wp_parse_args( $args, $defaults );
    462465
    463     if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {
     466    if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] )
    464467        $r['pad_counts'] = true;
    465     }
    466 
    467     if ( isset( $r['show_date'] ) ) {
     468
     469    if ( isset( $r['show_date'] ) )
    468470        $r['include_last_update_time'] = $r['show_date'];
    469     }
    470471
    471472    if ( true == $r['hierarchical'] ) {
     
    473474        $r['exclude'] = '';
    474475    }
     476   
     477    if ( !isset( $r['class'] ) )
     478        $r['class'] = ( 'category' == $r['taxonomy'] ) ? 'categories' : $r['taxonomy'];
    475479
    476480    extract( $r );
     481
     482    if ( !is_taxonomy($taxonomy) )
     483        return false;
    477484
    478485    $categories = get_categories( $r );
     
    480487    $output = '';
    481488    if ( $title_li && 'list' == $style )
    482             $output = '<li class="categories">' . $r['title_li'] . '<ul>';
     489            $output = '<li class="' . $class . '">' . $title_li . '<ul>';
    483490
    484491    if ( empty( $categories ) ) {
    485         if ( 'list' == $style )
    486             $output .= '<li>' . __( "No categories" ) . '</li>';
    487         else
    488             $output .= __( "No categories" );
     492        if ( ! empty( $show_option_none ) ) {
     493            if ( 'list' == $style )
     494                $output .= '<li>' . $show_option_none . '</li>';
     495            else
     496                $output .= $show_option_none;
     497        }
    489498    } else {
    490499        global $wp_query;
     
    496505                $output .= '<a href="' .  get_bloginfo( 'url' )  . '">' . $show_option_all . '</a>';
    497506
    498         if ( empty( $r['current_category'] ) && is_category() )
     507        if ( empty( $r['current_category'] ) && ( is_category() || is_tax() ) )
    499508            $r['current_category'] = $wp_query->get_queried_object_id();
    500509
Note: See TracChangeset for help on using the changeset viewer.