51 * @param int $depth Optional. Depth of category. Used for tab indentation. Default 0. |
51 * @param int $depth Optional. Depth of category. Used for tab indentation. Default 0. |
52 * @param array $args Optional. An array of arguments. Will only append content if style argument |
52 * @param array $args Optional. An array of arguments. Will only append content if style argument |
53 * value is 'list'. See wp_list_categories(). Default empty array. |
53 * value is 'list'. See wp_list_categories(). Default empty array. |
54 */ |
54 */ |
55 public function start_lvl( &$output, $depth = 0, $args = array() ) { |
55 public function start_lvl( &$output, $depth = 0, $args = array() ) { |
56 if ( 'list' != $args['style'] ) { |
56 if ( 'list' !== $args['style'] ) { |
57 return; |
57 return; |
58 } |
58 } |
59 |
59 |
60 $indent = str_repeat( "\t", $depth ); |
60 $indent = str_repeat( "\t", $depth ); |
61 $output .= "$indent<ul class='children'>\n"; |
61 $output .= "$indent<ul class='children'>\n"; |
72 * @param int $depth Optional. Depth of category. Used for tab indentation. Default 0. |
72 * @param int $depth Optional. Depth of category. Used for tab indentation. Default 0. |
73 * @param array $args Optional. An array of arguments. Will only append content if style argument |
73 * @param array $args Optional. An array of arguments. Will only append content if style argument |
74 * value is 'list'. See wp_list_categories(). Default empty array. |
74 * value is 'list'. See wp_list_categories(). Default empty array. |
75 */ |
75 */ |
76 public function end_lvl( &$output, $depth = 0, $args = array() ) { |
76 public function end_lvl( &$output, $depth = 0, $args = array() ) { |
77 if ( 'list' != $args['style'] ) { |
77 if ( 'list' !== $args['style'] ) { |
78 return; |
78 return; |
79 } |
79 } |
80 |
80 |
81 $indent = str_repeat( "\t", $depth ); |
81 $indent = str_repeat( "\t", $depth ); |
82 $output .= "$indent</ul>\n"; |
82 $output .= "$indent</ul>\n"; |
95 * @param array $args Optional. An array of arguments. See wp_list_categories(). Default empty array. |
95 * @param array $args Optional. An array of arguments. See wp_list_categories(). Default empty array. |
96 * @param int $id Optional. ID of the current category. Default 0. |
96 * @param int $id Optional. ID of the current category. Default 0. |
97 */ |
97 */ |
98 public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) { |
98 public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) { |
99 /** This filter is documented in wp-includes/category-template.php */ |
99 /** This filter is documented in wp-includes/category-template.php */ |
100 $cat_name = apply_filters( |
100 $cat_name = apply_filters( 'list_cats', esc_attr( $category->name ), $category ); |
101 'list_cats', |
|
102 esc_attr( $category->name ), |
|
103 $category |
|
104 ); |
|
105 |
101 |
106 // Don't generate an element if the category name is empty. |
102 // Don't generate an element if the category name is empty. |
107 if ( '' === $cat_name ) { |
103 if ( '' === $cat_name ) { |
108 return; |
104 return; |
109 } |
105 } |
141 */ |
137 */ |
142 $atts = apply_filters( 'category_list_link_attributes', $atts, $category, $depth, $args, $id ); |
138 $atts = apply_filters( 'category_list_link_attributes', $atts, $category, $depth, $args, $id ); |
143 |
139 |
144 $attributes = ''; |
140 $attributes = ''; |
145 foreach ( $atts as $attr => $value ) { |
141 foreach ( $atts as $attr => $value ) { |
146 if ( ! empty( $value ) ) { |
142 if ( is_scalar( $value ) && '' !== $value && false !== $value ) { |
147 $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); |
143 $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); |
148 $attributes .= ' ' . $attr . '="' . $value . '"'; |
144 $attributes .= ' ' . $attr . '="' . $value . '"'; |
149 } |
145 } |
150 } |
146 } |
151 |
147 |
163 } |
159 } |
164 |
160 |
165 $link .= '<a href="' . esc_url( get_term_feed_link( $category->term_id, $category->taxonomy, $args['feed_type'] ) ) . '"'; |
161 $link .= '<a href="' . esc_url( get_term_feed_link( $category->term_id, $category->taxonomy, $args['feed_type'] ) ) . '"'; |
166 |
162 |
167 if ( empty( $args['feed'] ) ) { |
163 if ( empty( $args['feed'] ) ) { |
168 /* translators: %s: category name */ |
164 /* translators: %s: Category name. */ |
169 $alt = ' alt="' . sprintf( __( 'Feed for all posts filed under %s' ), $cat_name ) . '"'; |
165 $alt = ' alt="' . sprintf( __( 'Feed for all posts filed under %s' ), $cat_name ) . '"'; |
170 } else { |
166 } else { |
171 $alt = ' alt="' . $args['feed'] . '"'; |
167 $alt = ' alt="' . $args['feed'] . '"'; |
172 $name = $args['feed']; |
168 $name = $args['feed']; |
173 $link .= empty( $args['title'] ) ? '' : $args['title']; |
169 $link .= empty( $args['title'] ) ? '' : $args['title']; |
188 } |
184 } |
189 |
185 |
190 if ( ! empty( $args['show_count'] ) ) { |
186 if ( ! empty( $args['show_count'] ) ) { |
191 $link .= ' (' . number_format_i18n( $category->count ) . ')'; |
187 $link .= ' (' . number_format_i18n( $category->count ) . ')'; |
192 } |
188 } |
193 if ( 'list' == $args['style'] ) { |
189 if ( 'list' === $args['style'] ) { |
194 $output .= "\t<li"; |
190 $output .= "\t<li"; |
195 $css_classes = array( |
191 $css_classes = array( |
196 'cat-item', |
192 'cat-item', |
197 'cat-item-' . $category->term_id, |
193 'cat-item-' . $category->term_id, |
198 ); |
194 ); |
199 |
195 |
200 if ( ! empty( $args['current_category'] ) ) { |
196 if ( ! empty( $args['current_category'] ) ) { |
201 // 'current_category' can be an array, so we use `get_terms()`. |
197 // 'current_category' can be an array, so we use `get_terms()`. |
202 $_current_terms = get_terms( |
198 $_current_terms = get_terms( |
203 $category->taxonomy, |
|
204 array( |
199 array( |
|
200 'taxonomy' => $category->taxonomy, |
205 'include' => $args['current_category'], |
201 'include' => $args['current_category'], |
206 'hide_empty' => false, |
202 'hide_empty' => false, |
207 ) |
203 ) |
208 ); |
204 ); |
209 |
205 |
210 foreach ( $_current_terms as $_current_term ) { |
206 foreach ( $_current_terms as $_current_term ) { |
211 if ( $category->term_id == $_current_term->term_id ) { |
207 if ( $category->term_id == $_current_term->term_id ) { |
212 $css_classes[] = 'current-cat'; |
208 $css_classes[] = 'current-cat'; |
|
209 $link = str_replace( '<a', '<a aria-current="page"', $link ); |
213 } elseif ( $category->term_id == $_current_term->parent ) { |
210 } elseif ( $category->term_id == $_current_term->parent ) { |
214 $css_classes[] = 'current-cat-parent'; |
211 $css_classes[] = 'current-cat-parent'; |
215 } |
212 } |
216 while ( $_current_term->parent ) { |
213 while ( $_current_term->parent ) { |
217 if ( $category->term_id == $_current_term->parent ) { |
214 if ( $category->term_id == $_current_term->parent ) { |
259 * @param int $depth Optional. Depth of category. Not used. |
256 * @param int $depth Optional. Depth of category. Not used. |
260 * @param array $args Optional. An array of arguments. Only uses 'list' for whether should append |
257 * @param array $args Optional. An array of arguments. Only uses 'list' for whether should append |
261 * to output. See wp_list_categories(). Default empty array. |
258 * to output. See wp_list_categories(). Default empty array. |
262 */ |
259 */ |
263 public function end_el( &$output, $page, $depth = 0, $args = array() ) { |
260 public function end_el( &$output, $page, $depth = 0, $args = array() ) { |
264 if ( 'list' != $args['style'] ) { |
261 if ( 'list' !== $args['style'] ) { |
265 return; |
262 return; |
266 } |
263 } |
267 |
264 |
268 $output .= "</li>\n"; |
265 $output .= "</li>\n"; |
269 } |
266 } |