151 * @param int $post_id Optional. Post ID to retrieve categories. |
158 * @param int $post_id Optional. Post ID to retrieve categories. |
152 * @return string |
159 * @return string |
153 */ |
160 */ |
154 function get_the_category_list( $separator = '', $parents='', $post_id = false ) { |
161 function get_the_category_list( $separator = '', $parents='', $post_id = false ) { |
155 global $wp_rewrite; |
162 global $wp_rewrite; |
156 if ( ! is_object_in_taxonomy( get_post_type( $post_id ), 'category' ) ) |
163 if ( ! is_object_in_taxonomy( get_post_type( $post_id ), 'category' ) ) { |
|
164 /** This filter is documented in wp-includes/category-template.php */ |
157 return apply_filters( 'the_category', '', $separator, $parents ); |
165 return apply_filters( 'the_category', '', $separator, $parents ); |
|
166 } |
158 |
167 |
159 $categories = get_the_category( $post_id ); |
168 $categories = get_the_category( $post_id ); |
160 if ( empty( $categories ) ) |
169 if ( empty( $categories ) ) { |
|
170 /** This filter is documented in wp-includes/category-template.php */ |
161 return apply_filters( 'the_category', __( 'Uncategorized' ), $separator, $parents ); |
171 return apply_filters( 'the_category', __( 'Uncategorized' ), $separator, $parents ); |
|
172 } |
162 |
173 |
163 $rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? 'rel="category tag"' : 'rel="category"'; |
174 $rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? 'rel="category tag"' : 'rel="category"'; |
164 |
175 |
165 $thelist = ''; |
176 $thelist = ''; |
166 if ( '' == $separator ) { |
177 if ( '' == $separator ) { |
169 $thelist .= "\n\t<li>"; |
180 $thelist .= "\n\t<li>"; |
170 switch ( strtolower( $parents ) ) { |
181 switch ( strtolower( $parents ) ) { |
171 case 'multiple': |
182 case 'multiple': |
172 if ( $category->parent ) |
183 if ( $category->parent ) |
173 $thelist .= get_category_parents( $category->parent, true, $separator ); |
184 $thelist .= get_category_parents( $category->parent, true, $separator ); |
174 $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>' . $category->name.'</a></li>'; |
185 $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a></li>'; |
175 break; |
186 break; |
176 case 'single': |
187 case 'single': |
177 $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>'; |
188 $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>'; |
178 if ( $category->parent ) |
189 if ( $category->parent ) |
179 $thelist .= get_category_parents( $category->parent, false, $separator ); |
190 $thelist .= get_category_parents( $category->parent, false, $separator ); |
180 $thelist .= $category->name.'</a></li>'; |
191 $thelist .= $category->name.'</a></li>'; |
181 break; |
192 break; |
182 case '': |
193 case '': |
183 default: |
194 default: |
184 $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>' . $category->name.'</a></li>'; |
195 $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a></li>'; |
185 } |
196 } |
186 } |
197 } |
187 $thelist .= '</ul>'; |
198 $thelist .= '</ul>'; |
188 } else { |
199 } else { |
189 $i = 0; |
200 $i = 0; |
192 $thelist .= $separator; |
203 $thelist .= $separator; |
193 switch ( strtolower( $parents ) ) { |
204 switch ( strtolower( $parents ) ) { |
194 case 'multiple': |
205 case 'multiple': |
195 if ( $category->parent ) |
206 if ( $category->parent ) |
196 $thelist .= get_category_parents( $category->parent, true, $separator ); |
207 $thelist .= get_category_parents( $category->parent, true, $separator ); |
197 $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>' . $category->name.'</a>'; |
208 $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a>'; |
198 break; |
209 break; |
199 case 'single': |
210 case 'single': |
200 $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>'; |
211 $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>'; |
201 if ( $category->parent ) |
212 if ( $category->parent ) |
202 $thelist .= get_category_parents( $category->parent, false, $separator ); |
213 $thelist .= get_category_parents( $category->parent, false, $separator ); |
203 $thelist .= "$category->name</a>"; |
214 $thelist .= "$category->name</a>"; |
204 break; |
215 break; |
205 case '': |
216 case '': |
206 default: |
217 default: |
207 $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" ' . $rel . '>' . $category->name.'</a>'; |
218 $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a>'; |
208 } |
219 } |
209 ++$i; |
220 ++$i; |
210 } |
221 } |
211 } |
222 } |
|
223 |
|
224 /** |
|
225 * Filter the category or list of categories. |
|
226 * |
|
227 * @since 1.2.0 |
|
228 * |
|
229 * @param array $thelist List of categories for the current post. |
|
230 * @param string $separator Separator used between the categories. |
|
231 * @param string $parents How to display the category parents. Accepts 'multiple', |
|
232 * 'single', or empty. |
|
233 */ |
212 return apply_filters( 'the_category', $thelist, $separator, $parents ); |
234 return apply_filters( 'the_category', $thelist, $separator, $parents ); |
213 } |
235 } |
214 |
236 |
215 /** |
237 /** |
216 * Check if the current post in within any of the given categories. |
238 * Check if the current post in within any of the given categories. |
263 return term_description( $category, 'category' ); |
284 return term_description( $category, 'category' ); |
264 } |
285 } |
265 |
286 |
266 /** |
287 /** |
267 * Display or retrieve the HTML dropdown list of categories. |
288 * Display or retrieve the HTML dropdown list of categories. |
268 * |
|
269 * The list of arguments is below: |
|
270 * 'show_option_all' (string) - Text to display for showing all categories. |
|
271 * 'show_option_none' (string) - Text to display for showing no categories. |
|
272 * 'orderby' (string) default is 'ID' - What column to use for ordering the |
|
273 * categories. |
|
274 * 'order' (string) default is 'ASC' - What direction to order categories. |
|
275 * 'show_count' (bool|int) default is 0 - Whether to show how many posts are |
|
276 * in the category. |
|
277 * 'hide_empty' (bool|int) default is 1 - Whether to hide categories that |
|
278 * don't have any posts attached to them. |
|
279 * 'child_of' (int) default is 0 - See {@link get_categories()}. |
|
280 * 'exclude' (string) - See {@link get_categories()}. |
|
281 * 'echo' (bool|int) default is 1 - Whether to display or retrieve content. |
|
282 * 'depth' (int) - The max depth. |
|
283 * 'tab_index' (int) - Tab index for select element. |
|
284 * 'name' (string) - The name attribute value for select element. |
|
285 * 'id' (string) - The ID attribute value for select element. Defaults to name if omitted. |
|
286 * 'class' (string) - The class attribute value for select element. |
|
287 * 'selected' (int) - Which category ID is selected. |
|
288 * 'taxonomy' (string) - The name of the taxonomy to retrieve. Defaults to category. |
|
289 * |
289 * |
290 * The 'hierarchical' argument, which is disabled by default, will override the |
290 * The 'hierarchical' argument, which is disabled by default, will override the |
291 * depth argument, unless it is true. When the argument is false, it will |
291 * depth argument, unless it is true. When the argument is false, it will |
292 * display all of the categories. When it is enabled it will use the value in |
292 * display all of the categories. When it is enabled it will use the value in |
293 * the 'depth' argument. |
293 * the 'depth' argument. |
294 * |
294 * |
295 * @since 2.1.0 |
295 * @since 2.1.0 |
296 * |
296 * @since 4.2.0 Introduced the `value_field` argument. |
297 * @param string|array $args Optional. Override default arguments. |
297 * |
|
298 * @param string|array $args { |
|
299 * Optional. Array or string of arguments to generate a categories drop-down element. |
|
300 * |
|
301 * @type string $show_option_all Text to display for showing all categories. Default empty. |
|
302 * @type string $show_option_none Text to display for showing no categories. Default empty. |
|
303 * @type string $option_none_value Value to use when no category is selected. Default empty. |
|
304 * @type string $orderby Which column to use for ordering categories. See get_terms() for a list |
|
305 * of accepted values. Default 'id' (term_id). |
|
306 * @type string $order Whether to order terms in ascending or descending order. Accepts 'ASC' |
|
307 * or 'DESC'. Default 'ASC'. |
|
308 * @type bool $pad_counts See get_terms() for an argument description. Default false. |
|
309 * @type bool|int $show_count Whether to include post counts. Accepts 0, 1, or their bool equivalents. |
|
310 * Default 0. |
|
311 * @type bool|int $hide_empty Whether to hide categories that don't have any posts. Accepts 0, 1, or |
|
312 * their bool equivalents. Default 1. |
|
313 * @type int $child_of Term ID to retrieve child terms of. See get_terms(). Default 0. |
|
314 * @type array|string $exclude Array or comma/space-separated string of term ids to exclude. |
|
315 * If `$include` is non-empty, `$exclude` is ignored. Default empty array. |
|
316 * @type bool|int $echo Whether to echo or return the generated markup. Accepts 0, 1, or their |
|
317 * bool equivalents. Default 1. |
|
318 * @type bool|int $hierarchical Whether to traverse the taxonomy hierarchy. Accepts 0, 1, or their bool |
|
319 * equivalents. Default 0. |
|
320 * @type int $depth Maximum depth. Default 0. |
|
321 * @type int $tab_index Tab index for the select element. Default 0 (no tabindex). |
|
322 * @type string $name Value for the 'name' attribute of the select element. Default 'cat'. |
|
323 * @type string $id Value for the 'id' attribute of the select element. Defaults to the value |
|
324 * of `$name`. |
|
325 * @type string $class Value for the 'class' attribute of the select element. Default 'postform'. |
|
326 * @type int|string $selected Value of the option that should be selected. Default 0. |
|
327 * @type string $value_field Term field that should be used to populate the 'value' attribute |
|
328 * of the option elements. Accepts any valid term field: 'term_id', 'name', |
|
329 * 'slug', 'term_group', 'term_taxonomy_id', 'taxonomy', 'description', |
|
330 * 'parent', 'count'. Default 'term_id'. |
|
331 * @type string $taxonomy Name of the category to retrieve. Default 'category'. |
|
332 * @type bool $hide_if_empty True to skip generating markup if no categories are found. |
|
333 * Default false (create select element even if no categories are found). |
|
334 * } |
298 * @return string HTML content only if 'echo' argument is 0. |
335 * @return string HTML content only if 'echo' argument is 0. |
299 */ |
336 */ |
300 function wp_dropdown_categories( $args = '' ) { |
337 function wp_dropdown_categories( $args = '' ) { |
301 $defaults = array( |
338 $defaults = array( |
302 'show_option_all' => '', 'show_option_none' => '', |
339 'show_option_all' => '', 'show_option_none' => '', |
318 _deprecated_argument( __FUNCTION__, '3.0', '' ); |
356 _deprecated_argument( __FUNCTION__, '3.0', '' ); |
319 $args['taxonomy'] = 'link_category'; |
357 $args['taxonomy'] = 'link_category'; |
320 } |
358 } |
321 |
359 |
322 $r = wp_parse_args( $args, $defaults ); |
360 $r = wp_parse_args( $args, $defaults ); |
323 |
361 $option_none_value = $r['option_none_value']; |
324 if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) { |
362 |
|
363 if ( ! isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) { |
325 $r['pad_counts'] = true; |
364 $r['pad_counts'] = true; |
326 } |
365 } |
327 |
366 |
328 extract( $r ); |
367 $tab_index = $r['tab_index']; |
329 |
368 |
330 $tab_index_attribute = ''; |
369 $tab_index_attribute = ''; |
331 if ( (int) $tab_index > 0 ) |
370 if ( (int) $tab_index > 0 ) { |
332 $tab_index_attribute = " tabindex=\"$tab_index\""; |
371 $tab_index_attribute = " tabindex=\"$tab_index\""; |
333 |
372 } |
334 $categories = get_terms( $taxonomy, $r ); |
373 |
335 $name = esc_attr( $name ); |
374 // Avoid clashes with the 'name' param of get_terms(). |
336 $class = esc_attr( $class ); |
375 $get_terms_args = $r; |
337 $id = $id ? esc_attr( $id ) : $name; |
376 unset( $get_terms_args['name'] ); |
338 |
377 $categories = get_terms( $r['taxonomy'], $get_terms_args ); |
339 if ( ! $r['hide_if_empty'] || ! empty($categories) ) |
378 |
|
379 $name = esc_attr( $r['name'] ); |
|
380 $class = esc_attr( $r['class'] ); |
|
381 $id = $r['id'] ? esc_attr( $r['id'] ) : $name; |
|
382 |
|
383 if ( ! $r['hide_if_empty'] || ! empty( $categories ) ) { |
340 $output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n"; |
384 $output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n"; |
341 else |
385 } else { |
342 $output = ''; |
386 $output = ''; |
343 |
387 } |
344 if ( empty($categories) && ! $r['hide_if_empty'] && !empty($show_option_none) ) { |
388 if ( empty( $categories ) && ! $r['hide_if_empty'] && ! empty( $r['show_option_none'] ) ) { |
345 $show_option_none = apply_filters( 'list_cats', $show_option_none ); |
389 |
346 $output .= "\t<option value='-1' selected='selected'>$show_option_none</option>\n"; |
390 /** |
|
391 * Filter a taxonomy drop-down display element. |
|
392 * |
|
393 * A variety of taxonomy drop-down display elements can be modified |
|
394 * just prior to display via this filter. Filterable arguments include |
|
395 * 'show_option_none', 'show_option_all', and various forms of the |
|
396 * term name. |
|
397 * |
|
398 * @since 1.2.0 |
|
399 * |
|
400 * @see wp_dropdown_categories() |
|
401 * |
|
402 * @param string $element Taxonomy element to list. |
|
403 */ |
|
404 $show_option_none = apply_filters( 'list_cats', $r['show_option_none'] ); |
|
405 $output .= "\t<option value='" . esc_attr( $option_none_value ) . "' selected='selected'>$show_option_none</option>\n"; |
347 } |
406 } |
348 |
407 |
349 if ( ! empty( $categories ) ) { |
408 if ( ! empty( $categories ) ) { |
350 |
409 |
351 if ( $show_option_all ) { |
410 if ( $r['show_option_all'] ) { |
352 $show_option_all = apply_filters( 'list_cats', $show_option_all ); |
411 |
|
412 /** This filter is documented in wp-includes/category-template.php */ |
|
413 $show_option_all = apply_filters( 'list_cats', $r['show_option_all'] ); |
353 $selected = ( '0' === strval($r['selected']) ) ? " selected='selected'" : ''; |
414 $selected = ( '0' === strval($r['selected']) ) ? " selected='selected'" : ''; |
354 $output .= "\t<option value='0'$selected>$show_option_all</option>\n"; |
415 $output .= "\t<option value='0'$selected>$show_option_all</option>\n"; |
355 } |
416 } |
356 |
417 |
357 if ( $show_option_none ) { |
418 if ( $r['show_option_none'] ) { |
358 $show_option_none = apply_filters( 'list_cats', $show_option_none ); |
419 |
359 $selected = ( '-1' === strval($r['selected']) ) ? " selected='selected'" : ''; |
420 /** This filter is documented in wp-includes/category-template.php */ |
360 $output .= "\t<option value='-1'$selected>$show_option_none</option>\n"; |
421 $show_option_none = apply_filters( 'list_cats', $r['show_option_none'] ); |
361 } |
422 $selected = selected( $option_none_value, $r['selected'], false ); |
362 |
423 $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$selected>$show_option_none</option>\n"; |
363 if ( $hierarchical ) |
424 } |
|
425 |
|
426 if ( $r['hierarchical'] ) { |
364 $depth = $r['depth']; // Walk the full depth. |
427 $depth = $r['depth']; // Walk the full depth. |
365 else |
428 } else { |
366 $depth = -1; // Flat. |
429 $depth = -1; // Flat. |
367 |
430 } |
368 $output .= walk_category_dropdown_tree( $categories, $depth, $r ); |
431 $output .= walk_category_dropdown_tree( $categories, $depth, $r ); |
369 } |
432 } |
370 |
433 |
371 if ( ! $r['hide_if_empty'] || ! empty($categories) ) |
434 if ( ! $r['hide_if_empty'] || ! empty( $categories ) ) { |
372 $output .= "</select>\n"; |
435 $output .= "</select>\n"; |
373 |
436 } |
374 $output = apply_filters( 'wp_dropdown_cats', $output ); |
437 /** |
375 |
438 * Filter the taxonomy drop-down output. |
376 if ( $echo ) |
439 * |
|
440 * @since 2.1.0 |
|
441 * |
|
442 * @param string $output HTML output. |
|
443 * @param array $r Arguments used to build the drop-down. |
|
444 */ |
|
445 $output = apply_filters( 'wp_dropdown_cats', $output, $r ); |
|
446 |
|
447 if ( $r['echo'] ) { |
377 echo $output; |
448 echo $output; |
378 |
449 } |
379 return $output; |
450 return $output; |
380 } |
451 } |
381 |
452 |
382 /** |
453 /** |
383 * Display or retrieve the HTML list of categories. |
454 * Display or retrieve the HTML list of categories. |
433 if ( true == $r['hierarchical'] ) { |
504 if ( true == $r['hierarchical'] ) { |
434 $r['exclude_tree'] = $r['exclude']; |
505 $r['exclude_tree'] = $r['exclude']; |
435 $r['exclude'] = ''; |
506 $r['exclude'] = ''; |
436 } |
507 } |
437 |
508 |
438 if ( !isset( $r['class'] ) ) |
509 if ( ! isset( $r['class'] ) ) |
439 $r['class'] = ( 'category' == $r['taxonomy'] ) ? 'categories' : $r['taxonomy']; |
510 $r['class'] = ( 'category' == $r['taxonomy'] ) ? 'categories' : $r['taxonomy']; |
440 |
511 |
441 extract( $r ); |
512 if ( ! taxonomy_exists( $r['taxonomy'] ) ) { |
442 |
|
443 if ( !taxonomy_exists($taxonomy) ) |
|
444 return false; |
513 return false; |
|
514 } |
|
515 |
|
516 $show_option_all = $r['show_option_all']; |
|
517 $show_option_none = $r['show_option_none']; |
445 |
518 |
446 $categories = get_categories( $r ); |
519 $categories = get_categories( $r ); |
447 |
520 |
448 $output = ''; |
521 $output = ''; |
449 if ( $title_li && 'list' == $style ) |
522 if ( $r['title_li'] && 'list' == $r['style'] ) { |
450 $output = '<li class="' . esc_attr( $class ) . '">' . $title_li . '<ul>'; |
523 $output = '<li class="' . esc_attr( $r['class'] ) . '">' . $r['title_li'] . '<ul>'; |
451 |
524 } |
452 if ( empty( $categories ) ) { |
525 if ( empty( $categories ) ) { |
453 if ( ! empty( $show_option_none ) ) { |
526 if ( ! empty( $show_option_none ) ) { |
454 if ( 'list' == $style ) |
527 if ( 'list' == $r['style'] ) { |
455 $output .= '<li>' . $show_option_none . '</li>'; |
528 $output .= '<li class="cat-item-none">' . $show_option_none . '</li>'; |
456 else |
529 } else { |
457 $output .= $show_option_none; |
530 $output .= $show_option_none; |
|
531 } |
458 } |
532 } |
459 } else { |
533 } else { |
460 if ( ! empty( $show_option_all ) ) { |
534 if ( ! empty( $show_option_all ) ) { |
461 $posts_page = ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) ) ? get_permalink( get_option( 'page_for_posts' ) ) : home_url( '/' ); |
535 $posts_page = ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) ) ? get_permalink( get_option( 'page_for_posts' ) ) : home_url( '/' ); |
462 $posts_page = esc_url( $posts_page ); |
536 $posts_page = esc_url( $posts_page ); |
463 if ( 'list' == $style ) |
537 if ( 'list' == $r['style'] ) { |
464 $output .= "<li><a href='$posts_page'>$show_option_all</a></li>"; |
538 $output .= "<li class='cat-item-all'><a href='$posts_page'>$show_option_all</a></li>"; |
465 else |
539 } else { |
466 $output .= "<a href='$posts_page'>$show_option_all</a>"; |
540 $output .= "<a href='$posts_page'>$show_option_all</a>"; |
|
541 } |
467 } |
542 } |
468 |
543 |
469 if ( empty( $r['current_category'] ) && ( is_category() || is_tax() || is_tag() ) ) { |
544 if ( empty( $r['current_category'] ) && ( is_category() || is_tax() || is_tag() ) ) { |
470 $current_term_object = get_queried_object(); |
545 $current_term_object = get_queried_object(); |
471 if ( $current_term_object && $r['taxonomy'] === $current_term_object->taxonomy ) |
546 if ( $current_term_object && $r['taxonomy'] === $current_term_object->taxonomy ) { |
472 $r['current_category'] = get_queried_object_id(); |
547 $r['current_category'] = get_queried_object_id(); |
473 } |
548 } |
474 |
549 } |
475 if ( $hierarchical ) |
550 |
|
551 if ( $r['hierarchical'] ) { |
476 $depth = $r['depth']; |
552 $depth = $r['depth']; |
477 else |
553 } else { |
478 $depth = -1; // Flat. |
554 $depth = -1; // Flat. |
479 |
555 } |
480 $output .= walk_category_tree( $categories, $depth, $r ); |
556 $output .= walk_category_tree( $categories, $depth, $r ); |
481 } |
557 } |
482 |
558 |
483 if ( $title_li && 'list' == $style ) |
559 if ( $r['title_li'] && 'list' == $r['style'] ) |
484 $output .= '</ul></li>'; |
560 $output .= '</ul></li>'; |
485 |
561 |
486 $output = apply_filters( 'wp_list_categories', $output, $args ); |
562 /** |
487 |
563 * Filter the HTML output of a taxonomy list. |
488 if ( $echo ) |
564 * |
489 echo $output; |
565 * @since 2.1.0 |
490 else |
566 * |
491 return $output; |
567 * @param string $output HTML output. |
|
568 * @param array $args An array of taxonomy-listing arguments. |
|
569 */ |
|
570 $html = apply_filters( 'wp_list_categories', $output, $args ); |
|
571 |
|
572 if ( $r['echo'] ) { |
|
573 echo $html; |
|
574 } else { |
|
575 return $html; |
|
576 } |
492 } |
577 } |
493 |
578 |
494 /** |
579 /** |
495 * Display tag cloud. |
580 * Display tag cloud. |
496 * |
581 * |
505 * The 'order' is the direction to sort, defaults to 'ASC' and can be 'DESC'. |
590 * The 'order' is the direction to sort, defaults to 'ASC' and can be 'DESC'. |
506 * |
591 * |
507 * The 'number' argument is how many tags to return. By default, the limit will |
592 * The 'number' argument is how many tags to return. By default, the limit will |
508 * be to return the top 45 tags in the tag cloud list. |
593 * be to return the top 45 tags in the tag cloud list. |
509 * |
594 * |
510 * The 'topic_count_text_callback' argument is a function, which, given the count |
595 * The 'topic_count_text' argument is a nooped plural from _n_noop() to generate the |
511 * of the posts with that tag, returns a text for the tooltip of the tag link. |
596 * text for the tooltip of the tag link. |
|
597 * |
|
598 * The 'topic_count_text_callback' argument is a function, which given the count |
|
599 * of the posts with that tag returns a text for the tooltip of the tag link. |
|
600 * |
|
601 * The 'post_type' argument is used only when 'link' is set to 'edit'. It determines the post_type |
|
602 * passed to edit.php for the popular tags edit links. |
512 * |
603 * |
513 * The 'exclude' and 'include' arguments are used for the {@link get_tags()} |
604 * The 'exclude' and 'include' arguments are used for the {@link get_tags()} |
514 * function. Only one should be used, because only one will be used and the |
605 * function. Only one should be used, because only one will be used and the |
515 * other ignored, if they are both set. |
606 * other ignored, if they are both set. |
516 * |
607 * |
517 * @since 2.3.0 |
608 * @since 2.3.0 |
518 * |
609 * |
519 * @param array|string $args Optional. Override default arguments. |
610 * @param array|string|null $args Optional. Override default arguments. |
520 * @return array Generated tag cloud, only if no failures and 'array' is set for the 'format' argument. |
611 * @return null|false Generated tag cloud, only if no failures and 'array' is set for the 'format' argument. |
521 */ |
612 */ |
522 function wp_tag_cloud( $args = '' ) { |
613 function wp_tag_cloud( $args = '' ) { |
523 $defaults = array( |
614 $defaults = array( |
524 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45, |
615 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45, |
525 'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC', |
616 'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC', |
526 'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'echo' => true |
617 'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'post_type' => '', 'echo' => true |
527 ); |
618 ); |
528 $args = wp_parse_args( $args, $defaults ); |
619 $args = wp_parse_args( $args, $defaults ); |
529 |
620 |
530 $tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags |
621 $tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags |
531 |
622 |
532 if ( empty( $tags ) || is_wp_error( $tags ) ) |
623 if ( empty( $tags ) || is_wp_error( $tags ) ) |
533 return; |
624 return; |
534 |
625 |
535 foreach ( $tags as $key => $tag ) { |
626 foreach ( $tags as $key => $tag ) { |
536 if ( 'edit' == $args['link'] ) |
627 if ( 'edit' == $args['link'] ) |
537 $link = get_edit_tag_link( $tag->term_id, $tag->taxonomy ); |
628 $link = get_edit_term_link( $tag->term_id, $tag->taxonomy, $args['post_type'] ); |
538 else |
629 else |
539 $link = get_term_link( intval($tag->term_id), $tag->taxonomy ); |
630 $link = get_term_link( intval($tag->term_id), $tag->taxonomy ); |
540 if ( is_wp_error( $link ) ) |
631 if ( is_wp_error( $link ) ) |
541 return false; |
632 return false; |
542 |
633 |
593 * 'RAND'. |
682 * 'RAND'. |
594 * |
683 * |
595 * The 'number' argument is how many tags to return. By default, the limit will |
684 * The 'number' argument is how many tags to return. By default, the limit will |
596 * be to return the entire tag cloud list. |
685 * be to return the entire tag cloud list. |
597 * |
686 * |
|
687 * The 'topic_count_text' argument is a nooped plural from _n_noop() to generate the |
|
688 * text for the tooltip of the tag link. |
|
689 * |
598 * The 'topic_count_text_callback' argument is a function, which given the count |
690 * The 'topic_count_text_callback' argument is a function, which given the count |
599 * of the posts with that tag returns a text for the tooltip of the tag link. |
691 * of the posts with that tag returns a text for the tooltip of the tag link. |
600 * |
692 * |
601 * @todo Complete functionality. |
693 * @todo Complete functionality. |
602 * @since 2.3.0 |
694 * @since 2.3.0 |
603 * |
695 * |
604 * @param array $tags List of tags. |
696 * @param array $tags List of tags. |
605 * @param string|array $args Optional, override default arguments. |
697 * @param string|array $args Optional, override default arguments. |
606 * @return string |
698 * @return string|array Tag cloud as a string or an array, depending on 'format' argument. |
607 */ |
699 */ |
608 function wp_generate_tag_cloud( $tags, $args = '' ) { |
700 function wp_generate_tag_cloud( $tags, $args = '' ) { |
609 $defaults = array( |
701 $defaults = array( |
610 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 0, |
702 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 0, |
611 'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC', |
703 'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC', |
612 'topic_count_text_callback' => 'default_topic_count_text', |
704 'topic_count_text' => null, 'topic_count_text_callback' => null, |
613 'topic_count_scale_callback' => 'default_topic_count_scale', 'filter' => 1, |
705 'topic_count_scale_callback' => 'default_topic_count_scale', 'filter' => 1, |
614 ); |
706 ); |
615 |
707 |
616 if ( !isset( $args['topic_count_text_callback'] ) && isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) { |
|
617 $body = 'return sprintf ( |
|
618 _n(' . var_export($args['single_text'], true) . ', ' . var_export($args['multiple_text'], true) . ', $count), |
|
619 number_format_i18n( $count ));'; |
|
620 $args['topic_count_text_callback'] = create_function('$count', $body); |
|
621 } |
|
622 |
|
623 $args = wp_parse_args( $args, $defaults ); |
708 $args = wp_parse_args( $args, $defaults ); |
624 extract( $args ); |
709 |
625 |
710 $return = ( 'array' === $args['format'] ) ? array() : ''; |
626 if ( empty( $tags ) ) |
711 |
627 return; |
712 if ( empty( $tags ) ) { |
628 |
713 return $return; |
|
714 } |
|
715 |
|
716 // Juggle topic count tooltips: |
|
717 if ( isset( $args['topic_count_text'] ) ) { |
|
718 // First look for nooped plural support via topic_count_text. |
|
719 $translate_nooped_plural = $args['topic_count_text']; |
|
720 } elseif ( ! empty( $args['topic_count_text_callback'] ) ) { |
|
721 // Look for the alternative callback style. Ignore the previous default. |
|
722 if ( $args['topic_count_text_callback'] === 'default_topic_count_text' ) { |
|
723 $translate_nooped_plural = _n_noop( '%s topic', '%s topics' ); |
|
724 } else { |
|
725 $translate_nooped_plural = false; |
|
726 } |
|
727 } elseif ( isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) { |
|
728 // If no callback exists, look for the old-style single_text and multiple_text arguments. |
|
729 $translate_nooped_plural = _n_noop( $args['single_text'], $args['multiple_text'] ); |
|
730 } else { |
|
731 // This is the default for when no callback, plural, or argument is passed in. |
|
732 $translate_nooped_plural = _n_noop( '%s topic', '%s topics' ); |
|
733 } |
|
734 |
|
735 /** |
|
736 * Filter how the items in a tag cloud are sorted. |
|
737 * |
|
738 * @since 2.8.0 |
|
739 * |
|
740 * @param array $tags Ordered array of terms. |
|
741 * @param array $args An array of tag cloud arguments. |
|
742 */ |
629 $tags_sorted = apply_filters( 'tag_cloud_sort', $tags, $args ); |
743 $tags_sorted = apply_filters( 'tag_cloud_sort', $tags, $args ); |
630 if ( $tags_sorted != $tags ) { // the tags have been sorted by a plugin |
744 if ( empty( $tags_sorted ) ) { |
|
745 return $return; |
|
746 } |
|
747 |
|
748 if ( $tags_sorted !== $tags ) { |
631 $tags = $tags_sorted; |
749 $tags = $tags_sorted; |
632 unset($tags_sorted); |
750 unset( $tags_sorted ); |
633 } else { |
751 } else { |
634 if ( 'RAND' == $order ) { |
752 if ( 'RAND' === $args['order'] ) { |
635 shuffle($tags); |
753 shuffle( $tags ); |
636 } else { |
754 } else { |
637 // SQL cannot save you; this is a second (potentially different) sort on a subset of data. |
755 // SQL cannot save you; this is a second (potentially different) sort on a subset of data. |
638 if ( 'name' == $orderby ) |
756 if ( 'name' === $args['orderby'] ) { |
639 uasort( $tags, '_wp_object_name_sort_cb' ); |
757 uasort( $tags, '_wp_object_name_sort_cb' ); |
640 else |
758 } else { |
641 uasort( $tags, '_wp_object_count_sort_cb' ); |
759 uasort( $tags, '_wp_object_count_sort_cb' ); |
642 |
760 } |
643 if ( 'DESC' == $order ) |
761 |
|
762 if ( 'DESC' === $args['order'] ) { |
644 $tags = array_reverse( $tags, true ); |
763 $tags = array_reverse( $tags, true ); |
645 } |
764 } |
646 } |
765 } |
647 |
766 } |
648 if ( $number > 0 ) |
767 |
649 $tags = array_slice($tags, 0, $number); |
768 if ( $args['number'] > 0 ) |
|
769 $tags = array_slice( $tags, 0, $args['number'] ); |
650 |
770 |
651 $counts = array(); |
771 $counts = array(); |
652 $real_counts = array(); // For the alt tag |
772 $real_counts = array(); // For the alt tag |
653 foreach ( (array) $tags as $key => $tag ) { |
773 foreach ( (array) $tags as $key => $tag ) { |
654 $real_counts[ $key ] = $tag->count; |
774 $real_counts[ $key ] = $tag->count; |
655 $counts[ $key ] = $topic_count_scale_callback($tag->count); |
775 $counts[ $key ] = call_user_func( $args['topic_count_scale_callback'], $tag->count ); |
656 } |
776 } |
657 |
777 |
658 $min_count = min( $counts ); |
778 $min_count = min( $counts ); |
659 $spread = max( $counts ) - $min_count; |
779 $spread = max( $counts ) - $min_count; |
660 if ( $spread <= 0 ) |
780 if ( $spread <= 0 ) |
661 $spread = 1; |
781 $spread = 1; |
662 $font_spread = $largest - $smallest; |
782 $font_spread = $args['largest'] - $args['smallest']; |
663 if ( $font_spread < 0 ) |
783 if ( $font_spread < 0 ) |
664 $font_spread = 1; |
784 $font_spread = 1; |
665 $font_step = $font_spread / $spread; |
785 $font_step = $font_spread / $spread; |
666 |
786 |
667 $a = array(); |
787 $a = array(); |
670 $count = $counts[ $key ]; |
790 $count = $counts[ $key ]; |
671 $real_count = $real_counts[ $key ]; |
791 $real_count = $real_counts[ $key ]; |
672 $tag_link = '#' != $tag->link ? esc_url( $tag->link ) : '#'; |
792 $tag_link = '#' != $tag->link ? esc_url( $tag->link ) : '#'; |
673 $tag_id = isset($tags[ $key ]->id) ? $tags[ $key ]->id : $key; |
793 $tag_id = isset($tags[ $key ]->id) ? $tags[ $key ]->id : $key; |
674 $tag_name = $tags[ $key ]->name; |
794 $tag_name = $tags[ $key ]->name; |
675 $a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . esc_attr( call_user_func( $topic_count_text_callback, $real_count, $tag, $args ) ) . "' style='font-size: " . |
795 |
676 str_replace( ',', '.', ( $smallest + ( ( $count - $min_count ) * $font_step ) ) ) |
796 if ( $translate_nooped_plural ) { |
677 . "$unit;'>$tag_name</a>"; |
797 $title_attribute = sprintf( translate_nooped_plural( $translate_nooped_plural, $real_count ), number_format_i18n( $real_count ) ); |
678 } |
798 } else { |
679 |
799 $title_attribute = call_user_func( $args['topic_count_text_callback'], $real_count, $tag, $args ); |
680 switch ( $format ) : |
800 } |
681 case 'array' : |
801 |
682 $return =& $a; |
802 $a[] = "<a href='$tag_link' class='tag-link-$tag_id' title='" . esc_attr( $title_attribute ) . "' style='font-size: " . |
683 break; |
803 str_replace( ',', '.', ( $args['smallest'] + ( ( $count - $min_count ) * $font_step ) ) ) |
684 case 'list' : |
804 . $args['unit'] . ";'>$tag_name</a>"; |
685 $return = "<ul class='wp-tag-cloud'>\n\t<li>"; |
805 } |
686 $return .= join( "</li>\n\t<li>", $a ); |
806 |
687 $return .= "</li>\n</ul>\n"; |
807 switch ( $args['format'] ) { |
688 break; |
808 case 'array' : |
689 default : |
809 $return =& $a; |
690 $return = join( $separator, $a ); |
810 break; |
691 break; |
811 case 'list' : |
692 endswitch; |
812 $return = "<ul class='wp-tag-cloud'>\n\t<li>"; |
693 |
813 $return .= join( "</li>\n\t<li>", $a ); |
694 if ( $filter ) |
814 $return .= "</li>\n</ul>\n"; |
|
815 break; |
|
816 default : |
|
817 $return = join( $args['separator'], $a ); |
|
818 break; |
|
819 } |
|
820 |
|
821 if ( $args['filter'] ) { |
|
822 /** |
|
823 * Filter the generated output of a tag cloud. |
|
824 * |
|
825 * The filter is only evaluated if a true value is passed |
|
826 * to the $filter argument in wp_generate_tag_cloud(). |
|
827 * |
|
828 * @since 2.3.0 |
|
829 * |
|
830 * @see wp_generate_tag_cloud() |
|
831 * |
|
832 * @param array|string $return String containing the generated HTML tag cloud output |
|
833 * or an array of tag links if the 'format' argument |
|
834 * equals 'array'. |
|
835 * @param array $tags An array of terms used in the tag cloud. |
|
836 * @param array $args An array of wp_generate_tag_cloud() arguments. |
|
837 */ |
695 return apply_filters( 'wp_generate_tag_cloud', $return, $tags, $args ); |
838 return apply_filters( 'wp_generate_tag_cloud', $return, $tags, $args ); |
|
839 } |
|
840 |
696 else |
841 else |
697 return $return; |
842 return $return; |
698 } |
843 } |
699 |
844 |
700 /** |
845 /** |
835 * @param object $category Category data object. |
980 * @param object $category Category data object. |
836 * @param int $depth Depth of category in reference to parents. Default 0. |
981 * @param int $depth Depth of category in reference to parents. Default 0. |
837 * @param array $args An array of arguments. @see wp_list_categories() |
982 * @param array $args An array of arguments. @see wp_list_categories() |
838 * @param int $id ID of the current category. |
983 * @param int $id ID of the current category. |
839 */ |
984 */ |
840 function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) { |
985 public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) { |
841 extract($args); |
986 /** This filter is documented in wp-includes/category-template.php */ |
842 |
987 $cat_name = apply_filters( |
843 $cat_name = esc_attr( $category->name ); |
988 'list_cats', |
844 $cat_name = apply_filters( 'list_cats', $cat_name, $category ); |
989 esc_attr( $category->name ), |
845 $link = '<a href="' . esc_url( get_term_link($category) ) . '" '; |
990 $category |
846 if ( $use_desc_for_title == 0 || empty($category->description) ) |
991 ); |
847 $link .= 'title="' . esc_attr( sprintf(__( 'View all posts filed under %s' ), $cat_name) ) . '"'; |
992 |
848 else |
993 // Don't generate an element if the category name is empty. |
|
994 if ( ! $cat_name ) { |
|
995 return; |
|
996 } |
|
997 |
|
998 $link = '<a href="' . esc_url( get_term_link( $category ) ) . '" '; |
|
999 if ( $args['use_desc_for_title'] && ! empty( $category->description ) ) { |
|
1000 /** |
|
1001 * Filter the category description for display. |
|
1002 * |
|
1003 * @since 1.2.0 |
|
1004 * |
|
1005 * @param string $description Category description. |
|
1006 * @param object $category Category object. |
|
1007 */ |
849 $link .= 'title="' . esc_attr( strip_tags( apply_filters( 'category_description', $category->description, $category ) ) ) . '"'; |
1008 $link .= 'title="' . esc_attr( strip_tags( apply_filters( 'category_description', $category->description, $category ) ) ) . '"'; |
|
1009 } |
|
1010 |
850 $link .= '>'; |
1011 $link .= '>'; |
851 $link .= $cat_name . '</a>'; |
1012 $link .= $cat_name . '</a>'; |
852 |
1013 |
853 if ( !empty($feed_image) || !empty($feed) ) { |
1014 if ( ! empty( $args['feed_image'] ) || ! empty( $args['feed'] ) ) { |
854 $link .= ' '; |
1015 $link .= ' '; |
855 |
1016 |
856 if ( empty($feed_image) ) |
1017 if ( empty( $args['feed_image'] ) ) { |
857 $link .= '('; |
1018 $link .= '('; |
858 |
1019 } |
859 $link .= '<a href="' . esc_url( get_term_feed_link( $category->term_id, $category->taxonomy, $feed_type ) ) . '"'; |
1020 |
860 |
1021 $link .= '<a href="' . esc_url( get_term_feed_link( $category->term_id, $category->taxonomy, $args['feed_type'] ) ) . '"'; |
861 if ( empty($feed) ) { |
1022 |
|
1023 if ( empty( $args['feed'] ) ) { |
862 $alt = ' alt="' . sprintf(__( 'Feed for all posts filed under %s' ), $cat_name ) . '"'; |
1024 $alt = ' alt="' . sprintf(__( 'Feed for all posts filed under %s' ), $cat_name ) . '"'; |
863 } else { |
1025 } else { |
864 $title = ' title="' . $feed . '"'; |
1026 $alt = ' alt="' . $args['feed'] . '"'; |
865 $alt = ' alt="' . $feed . '"'; |
1027 $name = $args['feed']; |
866 $name = $feed; |
1028 $link .= empty( $args['title'] ) ? '' : $args['title']; |
867 $link .= $title; |
|
868 } |
1029 } |
869 |
1030 |
870 $link .= '>'; |
1031 $link .= '>'; |
871 |
1032 |
872 if ( empty($feed_image) ) |
1033 if ( empty( $args['feed_image'] ) ) { |
873 $link .= $name; |
1034 $link .= $name; |
874 else |
1035 } else { |
875 $link .= "<img src='$feed_image'$alt$title" . ' />'; |
1036 $link .= "<img src='" . $args['feed_image'] . "'$alt" . ' />'; |
876 |
1037 } |
877 $link .= '</a>'; |
1038 $link .= '</a>'; |
878 |
1039 |
879 if ( empty($feed_image) ) |
1040 if ( empty( $args['feed_image'] ) ) { |
880 $link .= ')'; |
1041 $link .= ')'; |
881 } |
1042 } |
882 |
1043 } |
883 if ( !empty($show_count) ) |
1044 |
884 $link .= ' (' . intval($category->count) . ')'; |
1045 if ( ! empty( $args['show_count'] ) ) { |
885 |
1046 $link .= ' (' . number_format_i18n( $category->count ) . ')'; |
|
1047 } |
886 if ( 'list' == $args['style'] ) { |
1048 if ( 'list' == $args['style'] ) { |
887 $output .= "\t<li"; |
1049 $output .= "\t<li"; |
888 $class = 'cat-item cat-item-' . $category->term_id; |
1050 $css_classes = array( |
889 if ( !empty($current_category) ) { |
1051 'cat-item', |
890 $_current_category = get_term( $current_category, $category->taxonomy ); |
1052 'cat-item-' . $category->term_id, |
891 if ( $category->term_id == $current_category ) |
1053 ); |
892 $class .= ' current-cat'; |
1054 |
893 elseif ( $category->term_id == $_current_category->parent ) |
1055 if ( ! empty( $args['current_category'] ) ) { |
894 $class .= ' current-cat-parent'; |
1056 $_current_category = get_term( $args['current_category'], $category->taxonomy ); |
|
1057 if ( $category->term_id == $args['current_category'] ) { |
|
1058 $css_classes[] = 'current-cat'; |
|
1059 } elseif ( $category->term_id == $_current_category->parent ) { |
|
1060 $css_classes[] = 'current-cat-parent'; |
|
1061 } |
895 } |
1062 } |
896 $output .= ' class="' . $class . '"'; |
1063 |
|
1064 /** |
|
1065 * Filter the list of CSS classes to include with each category in the list. |
|
1066 * |
|
1067 * @since 4.2.0 |
|
1068 * |
|
1069 * @see wp_list_categories() |
|
1070 * |
|
1071 * @param array $css_classes An array of CSS classes to be applied to each list item. |
|
1072 * @param object $category Category data object. |
|
1073 * @param int $depth Depth of page, used for padding. |
|
1074 * @param array $args An array of wp_list_categories() arguments. |
|
1075 */ |
|
1076 $css_classes = implode( ' ', apply_filters( 'category_css_class', $css_classes, $category, $depth, $args ) ); |
|
1077 |
|
1078 $output .= ' class="' . $css_classes . '"'; |
897 $output .= ">$link\n"; |
1079 $output .= ">$link\n"; |
898 } else { |
1080 } else { |
899 $output .= "\t$link<br />\n"; |
1081 $output .= "\t$link<br />\n"; |
900 } |
1082 } |
901 } |
1083 } |
932 /** |
1114 /** |
933 * @see Walker::$tree_type |
1115 * @see Walker::$tree_type |
934 * @since 2.1.0 |
1116 * @since 2.1.0 |
935 * @var string |
1117 * @var string |
936 */ |
1118 */ |
937 var $tree_type = 'category'; |
1119 public $tree_type = 'category'; |
938 |
1120 |
939 /** |
1121 /** |
940 * @see Walker::$db_fields |
1122 * @see Walker::$db_fields |
941 * @since 2.1.0 |
1123 * @since 2.1.0 |
942 * @todo Decouple this |
1124 * @todo Decouple this |
943 * @var array |
1125 * @var array |
944 */ |
1126 */ |
945 var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); |
1127 public $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); |
946 |
1128 |
947 /** |
1129 /** |
948 * Start the element output. |
1130 * Start the element output. |
949 * |
1131 * |
950 * @see Walker::start_el() |
1132 * @see Walker::start_el() |
951 * @since 2.1.0 |
1133 * @since 2.1.0 |
952 * |
1134 * |
953 * @param string $output Passed by reference. Used to append additional content. |
1135 * @param string $output Passed by reference. Used to append additional content. |
954 * @param object $category Category data object. |
1136 * @param object $category Category data object. |
955 * @param int $depth Depth of category. Used for padding. |
1137 * @param int $depth Depth of category. Used for padding. |
956 * @param array $args Uses 'selected' and 'show_count' keys, if they exist. @see wp_dropdown_categories() |
1138 * @param array $args Uses 'selected', 'show_count', and 'value_field' keys, if they exist. |
957 */ |
1139 * See {@see wp_dropdown_categories()}. |
958 function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) { |
1140 */ |
|
1141 public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) { |
959 $pad = str_repeat(' ', $depth * 3); |
1142 $pad = str_repeat(' ', $depth * 3); |
960 |
1143 |
961 $cat_name = apply_filters('list_cats', $category->name, $category); |
1144 /** This filter is documented in wp-includes/category-template.php */ |
962 $output .= "\t<option class=\"level-$depth\" value=\"".$category->term_id."\""; |
1145 $cat_name = apply_filters( 'list_cats', $category->name, $category ); |
|
1146 |
|
1147 if ( ! isset( $args['value_field'] ) || ! isset( $category->{$args['value_field']} ) ) { |
|
1148 $args['value_field'] = 'term_id'; |
|
1149 } |
|
1150 |
|
1151 $output .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $category->{$args['value_field']} ) . "\""; |
|
1152 |
963 if ( $category->term_id == $args['selected'] ) |
1153 if ( $category->term_id == $args['selected'] ) |
964 $output .= ' selected="selected"'; |
1154 $output .= ' selected="selected"'; |
965 $output .= '>'; |
1155 $output .= '>'; |
966 $output .= $pad.$cat_name; |
1156 $output .= $pad.$cat_name; |
967 if ( $args['show_count'] ) |
1157 if ( $args['show_count'] ) |
968 $output .= ' ('. $category->count .')'; |
1158 $output .= ' ('. number_format_i18n( $category->count ) .')'; |
969 $output .= "</option>\n"; |
1159 $output .= "</option>\n"; |
970 } |
1160 } |
971 } |
1161 } |
972 |
1162 |
973 // |
1163 // |
997 |
1187 |
998 /** |
1188 /** |
999 * Retrieve the tags for a post. |
1189 * Retrieve the tags for a post. |
1000 * |
1190 * |
1001 * @since 2.3.0 |
1191 * @since 2.3.0 |
1002 * @uses apply_filters() Calls 'get_the_tags' filter on the list of post tags. |
|
1003 * |
1192 * |
1004 * @param int $id Post ID. |
1193 * @param int $id Post ID. |
1005 * @return array|bool Array of tag objects on success, false on failure. |
1194 * @return array|bool Array of tag objects on success, false on failure. |
1006 */ |
1195 */ |
1007 function get_the_tags( $id = 0 ) { |
1196 function get_the_tags( $id = 0 ) { |
|
1197 |
|
1198 /** |
|
1199 * Filter the array of tags for the given post. |
|
1200 * |
|
1201 * @since 2.3.0 |
|
1202 * |
|
1203 * @see get_the_terms() |
|
1204 * |
|
1205 * @param array $terms An array of tags for the given post. |
|
1206 */ |
1008 return apply_filters( 'get_the_tags', get_the_terms( $id, 'post_tag' ) ); |
1207 return apply_filters( 'get_the_tags', get_the_terms( $id, 'post_tag' ) ); |
1009 } |
1208 } |
1010 |
1209 |
1011 /** |
1210 /** |
1012 * Retrieve the tags for a post formatted as a string. |
1211 * Retrieve the tags for a post formatted as a string. |
1013 * |
1212 * |
1014 * @since 2.3.0 |
1213 * @since 2.3.0 |
1015 * @uses apply_filters() Calls 'the_tags' filter on string list of tags. |
|
1016 * |
1214 * |
1017 * @param string $before Optional. Before tags. |
1215 * @param string $before Optional. Before tags. |
1018 * @param string $sep Optional. Between tags. |
1216 * @param string $sep Optional. Between tags. |
1019 * @param string $after Optional. After tags. |
1217 * @param string $after Optional. After tags. |
1020 * @param int $id Optional. Post ID. Defaults to the current post. |
1218 * @param int $id Optional. Post ID. Defaults to the current post. |
1021 * @return string|bool|WP_Error A list of tags on success, false or WP_Error on failure. |
1219 * @return string|bool|WP_Error A list of tags on success, false if there are no terms, WP_Error on failure. |
1022 */ |
1220 */ |
1023 function get_the_tag_list( $before = '', $sep = '', $after = '', $id = 0 ) { |
1221 function get_the_tag_list( $before = '', $sep = '', $after = '', $id = 0 ) { |
|
1222 |
|
1223 /** |
|
1224 * Filter the tags list for a given post. |
|
1225 * |
|
1226 * @since 2.3.0 |
|
1227 * |
|
1228 * @param string $tag_list List of tags. |
|
1229 * @param string $before String to use before tags. |
|
1230 * @param string $sep String to use between the tags. |
|
1231 * @param string $after String to use after tags. |
|
1232 * @param int $id Post ID. |
|
1233 */ |
1024 return apply_filters( 'the_tags', get_the_term_list( $id, 'post_tag', $before, $sep, $after ), $before, $sep, $after, $id ); |
1234 return apply_filters( 'the_tags', get_the_term_list( $id, 'post_tag', $before, $sep, $after ), $before, $sep, $after, $id ); |
1025 } |
1235 } |
1026 |
1236 |
1027 /** |
1237 /** |
1028 * Retrieve the tags for a post. |
1238 * Retrieve the tags for a post. |
1107 * @param int $id Post ID. |
1327 * @param int $id Post ID. |
1108 * @param string $taxonomy Taxonomy name. |
1328 * @param string $taxonomy Taxonomy name. |
1109 * @param string $before Optional. Before list. |
1329 * @param string $before Optional. Before list. |
1110 * @param string $sep Optional. Separate items using this. |
1330 * @param string $sep Optional. Separate items using this. |
1111 * @param string $after Optional. After list. |
1331 * @param string $after Optional. After list. |
1112 * @return string|bool|WP_Error A list of terms on success, false or WP_Error on failure. |
1332 * @return string|bool|WP_Error A list of terms on success, false if there are no terms, WP_Error on failure. |
1113 */ |
1333 */ |
1114 function get_the_term_list( $id, $taxonomy, $before = '', $sep = '', $after = '' ) { |
1334 function get_the_term_list( $id, $taxonomy, $before = '', $sep = '', $after = '' ) { |
1115 $terms = get_the_terms( $id, $taxonomy ); |
1335 $terms = get_the_terms( $id, $taxonomy ); |
1116 |
1336 |
1117 if ( is_wp_error( $terms ) ) |
1337 if ( is_wp_error( $terms ) ) |
1118 return $terms; |
1338 return $terms; |
1119 |
1339 |
1120 if ( empty( $terms ) ) |
1340 if ( empty( $terms ) ) |
1121 return false; |
1341 return false; |
1122 |
1342 |
|
1343 $links = array(); |
|
1344 |
1123 foreach ( $terms as $term ) { |
1345 foreach ( $terms as $term ) { |
1124 $link = get_term_link( $term, $taxonomy ); |
1346 $link = get_term_link( $term, $taxonomy ); |
1125 if ( is_wp_error( $link ) ) |
1347 if ( is_wp_error( $link ) ) { |
1126 return $link; |
1348 return $link; |
1127 $term_links[] = '<a href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>'; |
1349 } |
1128 } |
1350 $links[] = '<a href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>'; |
1129 |
1351 } |
1130 $term_links = apply_filters( "term_links-$taxonomy", $term_links ); |
1352 |
|
1353 /** |
|
1354 * Filter the term links for a given taxonomy. |
|
1355 * |
|
1356 * The dynamic portion of the filter name, `$taxonomy`, refers |
|
1357 * to the taxonomy slug. |
|
1358 * |
|
1359 * @since 2.5.0 |
|
1360 * |
|
1361 * @param array $links An array of term links. |
|
1362 */ |
|
1363 $term_links = apply_filters( "term_links-$taxonomy", $links ); |
1131 |
1364 |
1132 return $before . join( $sep, $term_links ) . $after; |
1365 return $before . join( $sep, $term_links ) . $after; |
1133 } |
1366 } |
1134 |
1367 |
1135 /** |
1368 /** |
1140 * @param int $id Post ID. |
1373 * @param int $id Post ID. |
1141 * @param string $taxonomy Taxonomy name. |
1374 * @param string $taxonomy Taxonomy name. |
1142 * @param string $before Optional. Before list. |
1375 * @param string $before Optional. Before list. |
1143 * @param string $sep Optional. Separate items using this. |
1376 * @param string $sep Optional. Separate items using this. |
1144 * @param string $after Optional. After list. |
1377 * @param string $after Optional. After list. |
1145 * @return null|bool False on WordPress error. Returns null when displaying. |
1378 * @return false|null False on WordPress error. Returns null when displaying. |
1146 */ |
1379 */ |
1147 function the_terms( $id, $taxonomy, $before = '', $sep = ', ', $after = '' ) { |
1380 function the_terms( $id, $taxonomy, $before = '', $sep = ', ', $after = '' ) { |
1148 $term_list = get_the_term_list( $id, $taxonomy, $before, $sep, $after ); |
1381 $term_list = get_the_term_list( $id, $taxonomy, $before, $sep, $after ); |
1149 |
1382 |
1150 if ( is_wp_error( $term_list ) ) |
1383 if ( is_wp_error( $term_list ) ) |
1151 return false; |
1384 return false; |
1152 |
1385 |
1153 echo apply_filters('the_terms', $term_list, $taxonomy, $before, $sep, $after); |
1386 /** |
|
1387 * Filter the list of terms to display. |
|
1388 * |
|
1389 * @since 2.9.0 |
|
1390 * |
|
1391 * @param array $term_list List of terms to display. |
|
1392 * @param string $taxonomy The taxonomy name. |
|
1393 * @param string $before String to use before the terms. |
|
1394 * @param string $sep String to use between the terms. |
|
1395 * @param string $after String to use after the terms. |
|
1396 */ |
|
1397 echo apply_filters( 'the_terms', $term_list, $taxonomy, $before, $sep, $after ); |
1154 } |
1398 } |
1155 |
1399 |
1156 /** |
1400 /** |
1157 * Check if the current post has any of given category. |
1401 * Check if the current post has any of given category. |
1158 * |
1402 * |