From 8d990ce6f8e98c4bd87dceb1ca7b4bab00ef3e91 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Sat, 3 Jan 2015 02:30:14 +0000 Subject: [PATCH] Introduce 'category_css_classes' filter. Paralleling the 'page_css_classes' filter, this allows developers to modify the list of CSS classes used when creating category list markup via `Walker_Category`. Props sivel. Fixes #16497. git-svn-id: https://develop.svn.wordpress.org/trunk@31027 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/category-template.php | 28 +++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/category-template.php b/src/wp-includes/category-template.php index ad66987f7b..264a0d6355 100644 --- a/src/wp-includes/category-template.php +++ b/src/wp-includes/category-template.php @@ -1053,16 +1053,36 @@ class Walker_Category extends Walker { } if ( 'list' == $args['style'] ) { $output .= "\tterm_id; + $css_classes = array( + 'cat-item', + 'cat-item-' . $category->term_id, + ); + if ( ! empty( $args['current_category'] ) ) { $_current_category = get_term( $args['current_category'], $category->taxonomy ); if ( $category->term_id == $args['current_category'] ) { - $class .= ' current-cat'; + $css_classes[] = 'current-cat'; } elseif ( $category->term_id == $_current_category->parent ) { - $class .= ' current-cat-parent'; + $css_classes[] = 'current-cat-parent'; } } - $output .= ' class="' . $class . '"'; + + /** + * Filter the list of CSS classes to include with each category in the list. + * + * @since 4.2.0 + * + * @see wp_list_categories() + * + * @param array $css_classes An array of CSS classes to be applied + * to each list item. + * @param object $category Category data object. + * @param int $depth Depth of page, used for padding. + * @param array $args An array of arguments. + */ + $css_classes = implode( ' ', apply_filters( 'category_css_class', $css_classes, $category, $depth, $args ) ); + + $output .= ' class="' . $css_classes . '"'; $output .= ">$link\n"; } else { $output .= "\t$link
\n";