Update wp_list_categories() to be custom taxonomy aware. Props jfarthing84. See #11838
git-svn-id: http://svn.automattic.com/wordpress/trunk@13854 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
7bafa5ee43
commit
0e4aaa13d3
|
@ -448,44 +448,53 @@ function wp_dropdown_categories( $args = '' ) {
|
||||||
*/
|
*/
|
||||||
function wp_list_categories( $args = '' ) {
|
function wp_list_categories( $args = '' ) {
|
||||||
$defaults = array(
|
$defaults = array(
|
||||||
'show_option_all' => '', 'orderby' => 'name',
|
'show_option_all' => '', 'show_option_none' => __('No categories'),
|
||||||
'order' => 'ASC', 'show_last_update' => 0,
|
'orderby' => 'name', 'order' => 'ASC',
|
||||||
'style' => 'list', 'show_count' => 0,
|
'show_last_update' => 0, 'style' => 'list',
|
||||||
'hide_empty' => 1, 'use_desc_for_title' => 1,
|
'show_count' => 0, 'hide_empty' => 1,
|
||||||
'child_of' => 0, 'feed' => '', 'feed_type' => '',
|
'use_desc_for_title' => 1, 'child_of' => 0,
|
||||||
'feed_image' => '', 'exclude' => '', 'exclude_tree' => '', 'current_category' => 0,
|
'feed' => '', 'feed_type' => '',
|
||||||
|
'feed_image' => '', 'exclude' => '',
|
||||||
|
'exclude_tree' => '', 'current_category' => 0,
|
||||||
'hierarchical' => true, 'title_li' => __( 'Categories' ),
|
'hierarchical' => true, 'title_li' => __( 'Categories' ),
|
||||||
'echo' => 1, 'depth' => 0
|
'echo' => 1, 'depth' => 0,
|
||||||
|
'taxonomy' => 'category'
|
||||||
);
|
);
|
||||||
|
|
||||||
$r = wp_parse_args( $args, $defaults );
|
$r = wp_parse_args( $args, $defaults );
|
||||||
|
|
||||||
if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {
|
if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] )
|
||||||
$r['pad_counts'] = true;
|
$r['pad_counts'] = true;
|
||||||
}
|
|
||||||
|
|
||||||
if ( isset( $r['show_date'] ) ) {
|
if ( isset( $r['show_date'] ) )
|
||||||
$r['include_last_update_time'] = $r['show_date'];
|
$r['include_last_update_time'] = $r['show_date'];
|
||||||
}
|
|
||||||
|
|
||||||
if ( true == $r['hierarchical'] ) {
|
if ( true == $r['hierarchical'] ) {
|
||||||
$r['exclude_tree'] = $r['exclude'];
|
$r['exclude_tree'] = $r['exclude'];
|
||||||
$r['exclude'] = '';
|
$r['exclude'] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( !isset( $r['class'] ) )
|
||||||
|
$r['class'] = ( 'category' == $r['taxonomy'] ) ? 'categories' : $r['taxonomy'];
|
||||||
|
|
||||||
extract( $r );
|
extract( $r );
|
||||||
|
|
||||||
|
if ( !is_taxonomy($taxonomy) )
|
||||||
|
return false;
|
||||||
|
|
||||||
$categories = get_categories( $r );
|
$categories = get_categories( $r );
|
||||||
|
|
||||||
$output = '';
|
$output = '';
|
||||||
if ( $title_li && 'list' == $style )
|
if ( $title_li && 'list' == $style )
|
||||||
$output = '<li class="categories">' . $r['title_li'] . '<ul>';
|
$output = '<li class="' . $class . '">' . $title_li . '<ul>';
|
||||||
|
|
||||||
if ( empty( $categories ) ) {
|
if ( empty( $categories ) ) {
|
||||||
if ( 'list' == $style )
|
if ( ! empty( $show_option_none ) ) {
|
||||||
$output .= '<li>' . __( "No categories" ) . '</li>';
|
if ( 'list' == $style )
|
||||||
else
|
$output .= '<li>' . $show_option_none . '</li>';
|
||||||
$output .= __( "No categories" );
|
else
|
||||||
|
$output .= $show_option_none;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
global $wp_query;
|
global $wp_query;
|
||||||
|
|
||||||
|
@ -495,7 +504,7 @@ function wp_list_categories( $args = '' ) {
|
||||||
else
|
else
|
||||||
$output .= '<a href="' . get_bloginfo( 'url' ) . '">' . $show_option_all . '</a>';
|
$output .= '<a href="' . get_bloginfo( 'url' ) . '">' . $show_option_all . '</a>';
|
||||||
|
|
||||||
if ( empty( $r['current_category'] ) && is_category() )
|
if ( empty( $r['current_category'] ) && ( is_category() || is_tax() ) )
|
||||||
$r['current_category'] = $wp_query->get_queried_object_id();
|
$r['current_category'] = $wp_query->get_queried_object_id();
|
||||||
|
|
||||||
if ( $hierarchical )
|
if ( $hierarchical )
|
||||||
|
|
|
@ -1438,7 +1438,7 @@ class Walker_Category extends Walker {
|
||||||
|
|
||||||
$cat_name = esc_attr( $category->name);
|
$cat_name = esc_attr( $category->name);
|
||||||
$cat_name = apply_filters( 'list_cats', $cat_name, $category );
|
$cat_name = apply_filters( 'list_cats', $cat_name, $category );
|
||||||
$link = '<a href="' . get_category_link( $category->term_id ) . '" ';
|
$link = '<a href="' . get_term_link( $category, $category->taxonomy ) . '" ';
|
||||||
if ( $use_desc_for_title == 0 || empty($category->description) )
|
if ( $use_desc_for_title == 0 || empty($category->description) )
|
||||||
$link .= 'title="' . sprintf(__( 'View all posts filed under %s' ), $cat_name) . '"';
|
$link .= 'title="' . sprintf(__( 'View all posts filed under %s' ), $cat_name) . '"';
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue