]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/category-template.php
WordPress 4.7.2-scripts
[autoinstalls/wordpress.git] / wp-includes / category-template.php
1 <?php
2 /**
3  * Taxonomy API: Core category-specific template tags
4  *
5  * @package WordPress
6  * @subpackage Template
7  * @since 1.2.0
8  */
9
10 /**
11  * Retrieve category link URL.
12  *
13  * @since 1.0.0
14  * @see get_term_link()
15  *
16  * @param int|object $category Category ID or object.
17  * @return string Link on success, empty string if category does not exist.
18  */
19 function get_category_link( $category ) {
20         if ( ! is_object( $category ) )
21                 $category = (int) $category;
22
23         $category = get_term_link( $category, 'category' );
24
25         if ( is_wp_error( $category ) )
26                 return '';
27
28         return $category;
29 }
30
31 /**
32  * Retrieve category parents with separator.
33  *
34  * @since 1.2.0
35  *
36  * @param int $id Category ID.
37  * @param bool $link Optional, default is false. Whether to format with link.
38  * @param string $separator Optional, default is '/'. How to separate categories.
39  * @param bool $nicename Optional, default is false. Whether to use nice name for display.
40  * @param array $visited Optional. Already linked to categories to prevent duplicates.
41  * @return string|WP_Error A list of category parents on success, WP_Error on failure.
42  */
43 function get_category_parents( $id, $link = false, $separator = '/', $nicename = false, $visited = array() ) {
44         $chain = '';
45         $parent = get_term( $id, 'category' );
46         if ( is_wp_error( $parent ) )
47                 return $parent;
48
49         if ( $nicename )
50                 $name = $parent->slug;
51         else
52                 $name = $parent->name;
53
54         if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $visited ) ) {
55                 $visited[] = $parent->parent;
56                 $chain .= get_category_parents( $parent->parent, $link, $separator, $nicename, $visited );
57         }
58
59         if ( $link )
60                 $chain .= '<a href="' . esc_url( get_category_link( $parent->term_id ) ) . '">'.$name.'</a>' . $separator;
61         else
62                 $chain .= $name.$separator;
63         return $chain;
64 }
65
66 /**
67  * Retrieve post categories.
68  *
69  * This tag may be used outside The Loop by passing a post id as the parameter.
70  *
71  * Note: This function only returns results from the default "category" taxonomy.
72  * For custom taxonomies use get_the_terms().
73  *
74  * @since 0.71
75  *
76  * @param int $id Optional, default to current post ID. The post ID.
77  * @return array Array of WP_Term objects, one for each category assigned to the post.
78  */
79 function get_the_category( $id = false ) {
80         $categories = get_the_terms( $id, 'category' );
81         if ( ! $categories || is_wp_error( $categories ) )
82                 $categories = array();
83
84         $categories = array_values( $categories );
85
86         foreach ( array_keys( $categories ) as $key ) {
87                 _make_cat_compat( $categories[$key] );
88         }
89
90         /**
91          * Filters the array of categories to return for a post.
92          *
93          * @since 3.1.0
94          * @since 4.4.0 Added `$id` parameter.
95          *
96          * @param array $categories An array of categories to return for the post.
97          * @param int   $id         ID of the post.
98          */
99         return apply_filters( 'get_the_categories', $categories, $id );
100 }
101
102 /**
103  * Retrieve category name based on category ID.
104  *
105  * @since 0.71
106  *
107  * @param int $cat_ID Category ID.
108  * @return string|WP_Error Category name on success, WP_Error on failure.
109  */
110 function get_the_category_by_ID( $cat_ID ) {
111         $cat_ID = (int) $cat_ID;
112         $category = get_term( $cat_ID, 'category' );
113
114         if ( is_wp_error( $category ) )
115                 return $category;
116
117         return ( $category ) ? $category->name : '';
118 }
119
120 /**
121  * Retrieve category list in either HTML list or custom format.
122  *
123  * @since 1.5.1
124  *
125  * @global WP_Rewrite $wp_rewrite
126  *
127  * @param string $separator Optional, default is empty string. Separator for between the categories.
128  * @param string $parents Optional. How to display the parents.
129  * @param int $post_id Optional. Post ID to retrieve categories.
130  * @return string
131  */
132 function get_the_category_list( $separator = '', $parents='', $post_id = false ) {
133         global $wp_rewrite;
134         if ( ! is_object_in_taxonomy( get_post_type( $post_id ), 'category' ) ) {
135                 /** This filter is documented in wp-includes/category-template.php */
136                 return apply_filters( 'the_category', '', $separator, $parents );
137         }
138
139         /**
140          * Filters the categories before building the category list.
141          *
142          * @since 4.4.0
143          *
144          * @param array    $categories An array of the post's categories.
145          * @param int|bool $post_id    ID of the post we're retrieving categories for. When `false`, we assume the
146          *                             current post in the loop.
147          */
148         $categories = apply_filters( 'the_category_list', get_the_category( $post_id ), $post_id );
149
150         if ( empty( $categories ) ) {
151                 /** This filter is documented in wp-includes/category-template.php */
152                 return apply_filters( 'the_category', __( 'Uncategorized' ), $separator, $parents );
153         }
154
155         $rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? 'rel="category tag"' : 'rel="category"';
156
157         $thelist = '';
158         if ( '' == $separator ) {
159                 $thelist .= '<ul class="post-categories">';
160                 foreach ( $categories as $category ) {
161                         $thelist .= "\n\t<li>";
162                         switch ( strtolower( $parents ) ) {
163                                 case 'multiple':
164                                         if ( $category->parent )
165                                                 $thelist .= get_category_parents( $category->parent, true, $separator );
166                                         $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a></li>';
167                                         break;
168                                 case 'single':
169                                         $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '"  ' . $rel . '>';
170                                         if ( $category->parent )
171                                                 $thelist .= get_category_parents( $category->parent, false, $separator );
172                                         $thelist .= $category->name.'</a></li>';
173                                         break;
174                                 case '':
175                                 default:
176                                         $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a></li>';
177                         }
178                 }
179                 $thelist .= '</ul>';
180         } else {
181                 $i = 0;
182                 foreach ( $categories as $category ) {
183                         if ( 0 < $i )
184                                 $thelist .= $separator;
185                         switch ( strtolower( $parents ) ) {
186                                 case 'multiple':
187                                         if ( $category->parent )
188                                                 $thelist .= get_category_parents( $category->parent, true, $separator );
189                                         $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a>';
190                                         break;
191                                 case 'single':
192                                         $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>';
193                                         if ( $category->parent )
194                                                 $thelist .= get_category_parents( $category->parent, false, $separator );
195                                         $thelist .= "$category->name</a>";
196                                         break;
197                                 case '':
198                                 default:
199                                         $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a>';
200                         }
201                         ++$i;
202                 }
203         }
204
205         /**
206          * Filters the category or list of categories.
207          *
208          * @since 1.2.0
209          *
210          * @param array  $thelist   List of categories for the current post.
211          * @param string $separator Separator used between the categories.
212          * @param string $parents   How to display the category parents. Accepts 'multiple',
213          *                          'single', or empty.
214          */
215         return apply_filters( 'the_category', $thelist, $separator, $parents );
216 }
217
218 /**
219  * Check if the current post is within any of the given categories.
220  *
221  * The given categories are checked against the post's categories' term_ids, names and slugs.
222  * Categories given as integers will only be checked against the post's categories' term_ids.
223  *
224  * Prior to v2.5 of WordPress, category names were not supported.
225  * Prior to v2.7, category slugs were not supported.
226  * Prior to v2.7, only one category could be compared: in_category( $single_category ).
227  * Prior to v2.7, this function could only be used in the WordPress Loop.
228  * As of 2.7, the function can be used anywhere if it is provided a post ID or post object.
229  *
230  * @since 1.2.0
231  *
232  * @param int|string|array $category Category ID, name or slug, or array of said.
233  * @param int|object $post Optional. Post to check instead of the current post. (since 2.7.0)
234  * @return bool True if the current post is in any of the given categories.
235  */
236 function in_category( $category, $post = null ) {
237         if ( empty( $category ) )
238                 return false;
239
240         return has_category( $category, $post );
241 }
242
243 /**
244  * Display the category list for the post.
245  *
246  * @since 0.71
247  *
248  * @param string $separator Optional, default is empty string. Separator for between the categories.
249  * @param string $parents Optional. How to display the parents.
250  * @param int $post_id Optional. Post ID to retrieve categories.
251  */
252 function the_category( $separator = '', $parents='', $post_id = false ) {
253         echo get_the_category_list( $separator, $parents, $post_id );
254 }
255
256 /**
257  * Retrieve category description.
258  *
259  * @since 1.0.0
260  *
261  * @param int $category Optional. Category ID. Will use global category ID by default.
262  * @return string Category description, available.
263  */
264 function category_description( $category = 0 ) {
265         return term_description( $category, 'category' );
266 }
267
268 /**
269  * Display or retrieve the HTML dropdown list of categories.
270  *
271  * The 'hierarchical' argument, which is disabled by default, will override the
272  * depth argument, unless it is true. When the argument is false, it will
273  * display all of the categories. When it is enabled it will use the value in
274  * the 'depth' argument.
275  *
276  * @since 2.1.0
277  * @since 4.2.0 Introduced the `value_field` argument.
278  * @since 4.6.0 Introduced the `required` argument.
279  *
280  * @param string|array $args {
281  *     Optional. Array or string of arguments to generate a categories drop-down element.
282  *
283  *     @type string       $show_option_all   Text to display for showing all categories. Default empty.
284  *     @type string       $show_option_none  Text to display for showing no categories. Default empty.
285  *     @type string       $option_none_value Value to use when no category is selected. Default empty.
286  *     @type string       $orderby           Which column to use for ordering categories. See get_terms() for a list
287  *                                           of accepted values. Default 'id' (term_id).
288  *     @type string       $order             Whether to order terms in ascending or descending order. Accepts 'ASC'
289  *                                           or 'DESC'. Default 'ASC'.
290  *     @type bool         $pad_counts        See get_terms() for an argument description. Default false.
291  *     @type bool|int     $show_count        Whether to include post counts. Accepts 0, 1, or their bool equivalents.
292  *                                           Default 0.
293  *     @type bool|int     $hide_empty        Whether to hide categories that don't have any posts. Accepts 0, 1, or
294  *                                           their bool equivalents. Default 1.
295  *     @type int          $child_of          Term ID to retrieve child terms of. See get_terms(). Default 0.
296  *     @type array|string $exclude           Array or comma/space-separated string of term ids to exclude.
297  *                                           If `$include` is non-empty, `$exclude` is ignored. Default empty array.
298  *     @type bool|int     $echo              Whether to echo or return the generated markup. Accepts 0, 1, or their
299  *                                           bool equivalents. Default 1.
300  *     @type bool|int     $hierarchical      Whether to traverse the taxonomy hierarchy. Accepts 0, 1, or their bool
301  *                                           equivalents. Default 0.
302  *     @type int          $depth             Maximum depth. Default 0.
303  *     @type int          $tab_index         Tab index for the select element. Default 0 (no tabindex).
304  *     @type string       $name              Value for the 'name' attribute of the select element. Default 'cat'.
305  *     @type string       $id                Value for the 'id' attribute of the select element. Defaults to the value
306  *                                           of `$name`.
307  *     @type string       $class             Value for the 'class' attribute of the select element. Default 'postform'.
308  *     @type int|string   $selected          Value of the option that should be selected. Default 0.
309  *     @type string       $value_field       Term field that should be used to populate the 'value' attribute
310  *                                           of the option elements. Accepts any valid term field: 'term_id', 'name',
311  *                                           'slug', 'term_group', 'term_taxonomy_id', 'taxonomy', 'description',
312  *                                           'parent', 'count'. Default 'term_id'.
313  *     @type string|array $taxonomy          Name of the category or categories to retrieve. Default 'category'.
314  *     @type bool         $hide_if_empty     True to skip generating markup if no categories are found.
315  *                                           Default false (create select element even if no categories are found).
316  *     @type bool         $required          Whether the `<select>` element should have the HTML5 'required' attribute.
317  *                                           Default false.
318  * }
319  * @return string HTML content only if 'echo' argument is 0.
320  */
321 function wp_dropdown_categories( $args = '' ) {
322         $defaults = array(
323                 'show_option_all'   => '',
324                 'show_option_none'  => '',
325                 'orderby'           => 'id',
326                 'order'             => 'ASC',
327                 'show_count'        => 0,
328                 'hide_empty'        => 1,
329                 'child_of'          => 0,
330                 'exclude'           => '',
331                 'echo'              => 1,
332                 'selected'          => 0,
333                 'hierarchical'      => 0,
334                 'name'              => 'cat',
335                 'id'                => '',
336                 'class'             => 'postform',
337                 'depth'             => 0,
338                 'tab_index'         => 0,
339                 'taxonomy'          => 'category',
340                 'hide_if_empty'     => false,
341                 'option_none_value' => -1,
342                 'value_field'       => 'term_id',
343                 'required'          => false,
344         );
345
346         $defaults['selected'] = ( is_category() ) ? get_query_var( 'cat' ) : 0;
347
348         // Back compat.
349         if ( isset( $args['type'] ) && 'link' == $args['type'] ) {
350                 /* translators: 1: "type => link", 2: "taxonomy => link_category" alternative */
351                 _deprecated_argument( __FUNCTION__, '3.0.0',
352                         sprintf( __( '%1$s is deprecated. Use %2$s instead.' ),
353                                 '<code>type => link</code>',
354                                 '<code>taxonomy => link_category</code>'
355                         )
356                 );
357                 $args['taxonomy'] = 'link_category';
358         }
359
360         $r = wp_parse_args( $args, $defaults );
361         $option_none_value = $r['option_none_value'];
362
363         if ( ! isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) {
364                 $r['pad_counts'] = true;
365         }
366
367         $tab_index = $r['tab_index'];
368
369         $tab_index_attribute = '';
370         if ( (int) $tab_index > 0 ) {
371                 $tab_index_attribute = " tabindex=\"$tab_index\"";
372         }
373
374         // Avoid clashes with the 'name' param of get_terms().
375         $get_terms_args = $r;
376         unset( $get_terms_args['name'] );
377         $categories = get_terms( $r['taxonomy'], $get_terms_args );
378
379         $name = esc_attr( $r['name'] );
380         $class = esc_attr( $r['class'] );
381         $id = $r['id'] ? esc_attr( $r['id'] ) : $name;
382         $required = $r['required'] ? 'required' : '';
383
384         if ( ! $r['hide_if_empty'] || ! empty( $categories ) ) {
385                 $output = "<select $required name='$name' id='$id' class='$class' $tab_index_attribute>\n";
386         } else {
387                 $output = '';
388         }
389         if ( empty( $categories ) && ! $r['hide_if_empty'] && ! empty( $r['show_option_none'] ) ) {
390
391                 /**
392                  * Filters a taxonomy drop-down display element.
393                  *
394                  * A variety of taxonomy drop-down display elements can be modified
395                  * just prior to display via this filter. Filterable arguments include
396                  * 'show_option_none', 'show_option_all', and various forms of the
397                  * term name.
398                  *
399                  * @since 1.2.0
400                  *
401                  * @see wp_dropdown_categories()
402                  *
403                  * @param string $element Taxonomy element to list.
404                  */
405                 $show_option_none = apply_filters( 'list_cats', $r['show_option_none'] );
406                 $output .= "\t<option value='" . esc_attr( $option_none_value ) . "' selected='selected'>$show_option_none</option>\n";
407         }
408
409         if ( ! empty( $categories ) ) {
410
411                 if ( $r['show_option_all'] ) {
412
413                         /** This filter is documented in wp-includes/category-template.php */
414                         $show_option_all = apply_filters( 'list_cats', $r['show_option_all'] );
415                         $selected = ( '0' === strval($r['selected']) ) ? " selected='selected'" : '';
416                         $output .= "\t<option value='0'$selected>$show_option_all</option>\n";
417                 }
418
419                 if ( $r['show_option_none'] ) {
420
421                         /** This filter is documented in wp-includes/category-template.php */
422                         $show_option_none = apply_filters( 'list_cats', $r['show_option_none'] );
423                         $selected = selected( $option_none_value, $r['selected'], false );
424                         $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$selected>$show_option_none</option>\n";
425                 }
426
427                 if ( $r['hierarchical'] ) {
428                         $depth = $r['depth'];  // Walk the full depth.
429                 } else {
430                         $depth = -1; // Flat.
431                 }
432                 $output .= walk_category_dropdown_tree( $categories, $depth, $r );
433         }
434
435         if ( ! $r['hide_if_empty'] || ! empty( $categories ) ) {
436                 $output .= "</select>\n";
437         }
438         /**
439          * Filters the taxonomy drop-down output.
440          *
441          * @since 2.1.0
442          *
443          * @param string $output HTML output.
444          * @param array  $r      Arguments used to build the drop-down.
445          */
446         $output = apply_filters( 'wp_dropdown_cats', $output, $r );
447
448         if ( $r['echo'] ) {
449                 echo $output;
450         }
451         return $output;
452 }
453
454 /**
455  * Display or retrieve the HTML list of categories.
456  *
457  * @since 2.1.0
458  * @since 4.4.0 Introduced the `hide_title_if_empty` and `separator` arguments. The `current_category` argument was modified to
459  *              optionally accept an array of values.
460  *
461  * @param string|array $args {
462  *     Array of optional arguments.
463  *
464  *     @type int          $child_of              Term ID to retrieve child terms of. See get_terms(). Default 0.
465  *     @type int|array    $current_category      ID of category, or array of IDs of categories, that should get the
466  *                                               'current-cat' class. Default 0.
467  *     @type int          $depth                 Category depth. Used for tab indentation. Default 0.
468  *     @type bool|int     $echo                  True to echo markup, false to return it. Default 1.
469  *     @type array|string $exclude               Array or comma/space-separated string of term IDs to exclude.
470  *                                               If `$hierarchical` is true, descendants of `$exclude` terms will also
471  *                                               be excluded; see `$exclude_tree`. See get_terms().
472  *                                               Default empty string.
473  *     @type array|string $exclude_tree          Array or comma/space-separated string of term IDs to exclude, along
474  *                                               with their descendants. See get_terms(). Default empty string.
475  *     @type string       $feed                  Text to use for the feed link. Default 'Feed for all posts filed
476  *                                               under [cat name]'.
477  *     @type string       $feed_image            URL of an image to use for the feed link. Default empty string.
478  *     @type string       $feed_type             Feed type. Used to build feed link. See get_term_feed_link().
479  *                                               Default empty string (default feed).
480  *     @type bool|int     $hide_empty            Whether to hide categories that don't have any posts attached to them.
481  *                                               Default 1.
482  *     @type bool         $hide_title_if_empty   Whether to hide the `$title_li` element if there are no terms in
483  *                                               the list. Default false (title will always be shown).
484  *     @type bool         $hierarchical          Whether to include terms that have non-empty descendants.
485  *                                               See get_terms(). Default true.
486  *     @type string       $order                 Which direction to order categories. Accepts 'ASC' or 'DESC'.
487  *                                               Default 'ASC'.
488  *     @type string       $orderby               The column to use for ordering categories. Default 'ID'.
489  *     @type string       $separator             Separator between links. Default '<br />'.
490  *     @type bool|int     $show_count            Whether to show how many posts are in the category. Default 0.
491  *     @type string       $show_option_all       Text to display for showing all categories. Default empty string.
492  *     @type string       $show_option_none      Text to display for the 'no categories' option.
493  *                                               Default 'No categories'.
494  *     @type string       $style                 The style used to display the categories list. If 'list', categories
495  *                                               will be output as an unordered list. If left empty or another value,
496  *                                               categories will be output separated by `<br>` tags. Default 'list'.
497  *     @type string       $taxonomy              Taxonomy name. Default 'category'.
498  *     @type string       $title_li              Text to use for the list title `<li>` element. Pass an empty string
499  *                                               to disable. Default 'Categories'.
500  *     @type bool|int     $use_desc_for_title    Whether to use the category description as the title attribute.
501  *                                               Default 1.
502  * }
503  * @return false|string HTML content only if 'echo' argument is 0.
504  */
505 function wp_list_categories( $args = '' ) {
506         $defaults = array(
507                 'child_of'            => 0,
508                 'current_category'    => 0,
509                 'depth'               => 0,
510                 'echo'                => 1,
511                 'exclude'             => '',
512                 'exclude_tree'        => '',
513                 'feed'                => '',
514                 'feed_image'          => '',
515                 'feed_type'           => '',
516                 'hide_empty'          => 1,
517                 'hide_title_if_empty' => false,
518                 'hierarchical'        => true,
519                 'order'               => 'ASC',
520                 'orderby'             => 'name',
521                 'separator'           => '<br />',
522                 'show_count'          => 0,
523                 'show_option_all'     => '',
524                 'show_option_none'    => __( 'No categories' ),
525                 'style'               => 'list',
526                 'taxonomy'            => 'category',
527                 'title_li'            => __( 'Categories' ),
528                 'use_desc_for_title'  => 1,
529         );
530
531         $r = wp_parse_args( $args, $defaults );
532
533         if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] )
534                 $r['pad_counts'] = true;
535
536         // Descendants of exclusions should be excluded too.
537         if ( true == $r['hierarchical'] ) {
538                 $exclude_tree = array();
539
540                 if ( $r['exclude_tree'] ) {
541                         $exclude_tree = array_merge( $exclude_tree, wp_parse_id_list( $r['exclude_tree'] ) );
542                 }
543
544                 if ( $r['exclude'] ) {
545                         $exclude_tree = array_merge( $exclude_tree, wp_parse_id_list( $r['exclude'] ) );
546                 }
547
548                 $r['exclude_tree'] = $exclude_tree;
549                 $r['exclude'] = '';
550         }
551
552         if ( ! isset( $r['class'] ) )
553                 $r['class'] = ( 'category' == $r['taxonomy'] ) ? 'categories' : $r['taxonomy'];
554
555         if ( ! taxonomy_exists( $r['taxonomy'] ) ) {
556                 return false;
557         }
558
559         $show_option_all = $r['show_option_all'];
560         $show_option_none = $r['show_option_none'];
561
562         $categories = get_categories( $r );
563
564         $output = '';
565         if ( $r['title_li'] && 'list' == $r['style'] && ( ! empty( $categories ) || ! $r['hide_title_if_empty'] ) ) {
566                 $output = '<li class="' . esc_attr( $r['class'] ) . '">' . $r['title_li'] . '<ul>';
567         }
568         if ( empty( $categories ) ) {
569                 if ( ! empty( $show_option_none ) ) {
570                         if ( 'list' == $r['style'] ) {
571                                 $output .= '<li class="cat-item-none">' . $show_option_none . '</li>';
572                         } else {
573                                 $output .= $show_option_none;
574                         }
575                 }
576         } else {
577                 if ( ! empty( $show_option_all ) ) {
578
579                         $posts_page = '';
580
581                         // For taxonomies that belong only to custom post types, point to a valid archive.
582                         $taxonomy_object = get_taxonomy( $r['taxonomy'] );
583                         if ( ! in_array( 'post', $taxonomy_object->object_type ) && ! in_array( 'page', $taxonomy_object->object_type ) ) {
584                                 foreach ( $taxonomy_object->object_type as $object_type ) {
585                                         $_object_type = get_post_type_object( $object_type );
586
587                                         // Grab the first one.
588                                         if ( ! empty( $_object_type->has_archive ) ) {
589                                                 $posts_page = get_post_type_archive_link( $object_type );
590                                                 break;
591                                         }
592                                 }
593                         }
594
595                         // Fallback for the 'All' link is the posts page.
596                         if ( ! $posts_page ) {
597                                 if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) ) {
598                                         $posts_page = get_permalink( get_option( 'page_for_posts' ) );
599                                 } else {
600                                         $posts_page = home_url( '/' );
601                                 }
602                         }
603
604                         $posts_page = esc_url( $posts_page );
605                         if ( 'list' == $r['style'] ) {
606                                 $output .= "<li class='cat-item-all'><a href='$posts_page'>$show_option_all</a></li>";
607                         } else {
608                                 $output .= "<a href='$posts_page'>$show_option_all</a>";
609                         }
610                 }
611
612                 if ( empty( $r['current_category'] ) && ( is_category() || is_tax() || is_tag() ) ) {
613                         $current_term_object = get_queried_object();
614                         if ( $current_term_object && $r['taxonomy'] === $current_term_object->taxonomy ) {
615                                 $r['current_category'] = get_queried_object_id();
616                         }
617                 }
618
619                 if ( $r['hierarchical'] ) {
620                         $depth = $r['depth'];
621                 } else {
622                         $depth = -1; // Flat.
623                 }
624                 $output .= walk_category_tree( $categories, $depth, $r );
625         }
626
627         if ( $r['title_li'] && 'list' == $r['style'] && ( ! empty( $categories ) || ! $r['hide_title_if_empty'] ) ) {
628                 $output .= '</ul></li>';
629         }
630
631         /**
632          * Filters the HTML output of a taxonomy list.
633          *
634          * @since 2.1.0
635          *
636          * @param string $output HTML output.
637          * @param array  $args   An array of taxonomy-listing arguments.
638          */
639         $html = apply_filters( 'wp_list_categories', $output, $args );
640
641         if ( $r['echo'] ) {
642                 echo $html;
643         } else {
644                 return $html;
645         }
646 }
647
648 /**
649  * Display tag cloud.
650  *
651  * The text size is set by the 'smallest' and 'largest' arguments, which will
652  * use the 'unit' argument value for the CSS text size unit. The 'format'
653  * argument can be 'flat' (default), 'list', or 'array'. The flat value for the
654  * 'format' argument will separate tags with spaces. The list value for the
655  * 'format' argument will format the tags in a UL HTML list. The array value for
656  * the 'format' argument will return in PHP array type format.
657  *
658  * The 'orderby' argument will accept 'name' or 'count' and defaults to 'name'.
659  * The 'order' is the direction to sort, defaults to 'ASC' and can be 'DESC'.
660  *
661  * The 'number' argument is how many tags to return. By default, the limit will
662  * be to return the top 45 tags in the tag cloud list.
663  *
664  * The 'topic_count_text' argument is a nooped plural from _n_noop() to generate the
665  * text for the tooltip of the tag link.
666  *
667  * The 'topic_count_text_callback' argument is a function, which given the count
668  * of the posts with that tag returns a text for the tooltip of the tag link.
669  *
670  * The 'post_type' argument is used only when 'link' is set to 'edit'. It determines the post_type
671  * passed to edit.php for the popular tags edit links.
672  *
673  * The 'exclude' and 'include' arguments are used for the get_tags() function. Only one
674  * should be used, because only one will be used and the other ignored, if they are both set.
675  *
676  * @since 2.3.0
677  *
678  * @param array|string|null $args Optional. Override default arguments.
679  * @return void|array Generated tag cloud, only if no failures and 'array' is set for the 'format' argument.
680  *                    Otherwise, this function outputs the tag cloud.
681  */
682 function wp_tag_cloud( $args = '' ) {
683         $defaults = array(
684                 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
685                 'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC',
686                 'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'post_type' => '', 'echo' => true
687         );
688         $args = wp_parse_args( $args, $defaults );
689
690         $tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags
691
692         if ( empty( $tags ) || is_wp_error( $tags ) )
693                 return;
694
695         foreach ( $tags as $key => $tag ) {
696                 if ( 'edit' == $args['link'] )
697                         $link = get_edit_term_link( $tag->term_id, $tag->taxonomy, $args['post_type'] );
698                 else
699                         $link = get_term_link( intval($tag->term_id), $tag->taxonomy );
700                 if ( is_wp_error( $link ) )
701                         return;
702
703                 $tags[ $key ]->link = $link;
704                 $tags[ $key ]->id = $tag->term_id;
705         }
706
707         $return = wp_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args
708
709         /**
710          * Filters the tag cloud output.
711          *
712          * @since 2.3.0
713          *
714          * @param string $return HTML output of the tag cloud.
715          * @param array  $args   An array of tag cloud arguments.
716          */
717         $return = apply_filters( 'wp_tag_cloud', $return, $args );
718
719         if ( 'array' == $args['format'] || empty($args['echo']) )
720                 return $return;
721
722         echo $return;
723 }
724
725 /**
726  * Default topic count scaling for tag links
727  *
728  * @param int $count number of posts with that tag
729  * @return int scaled count
730  */
731 function default_topic_count_scale( $count ) {
732         return round(log10($count + 1) * 100);
733 }
734
735 /**
736  * Generates a tag cloud (heatmap) from provided data.
737  *
738  * @todo Complete functionality.
739  * @since 2.3.0
740  *
741  * @param array $tags List of tags.
742  * @param string|array $args {
743  *     Optional. Array of string of arguments for generating a tag cloud.
744  *
745  *     @type int      $smallest                   Smallest font size used to display tags. Paired
746  *                                                with the value of `$unit`, to determine CSS text
747  *                                                size unit. Default 8 (pt).
748  *     @type int      $largest                    Largest font size used to display tags. Paired
749  *                                                with the value of `$unit`, to determine CSS text
750  *                                                size unit. Default 22 (pt).
751  *     @type string   $unit                       CSS text size unit to use with the `$smallest`
752  *                                                and `$largest` values. Accepts any valid CSS text
753  *                                                size unit. Default 'pt'.
754  *     @type int      $number                     The number of tags to return. Accepts any
755  *                                                positive integer or zero to return all.
756  *                                                Default 0.
757  *     @type string   $format                     Format to display the tag cloud in. Accepts 'flat'
758  *                                                (tags separated with spaces), 'list' (tags displayed
759  *                                                in an unordered list), or 'array' (returns an array).
760  *                                                Default 'flat'.
761  *     @type string   $separator                  HTML or text to separate the tags. Default "\n" (newline).
762  *     @type string   $orderby                    Value to order tags by. Accepts 'name' or 'count'.
763  *                                                Default 'name'. The {@see 'tag_cloud_sort'} filter
764  *                                                can also affect how tags are sorted.
765  *     @type string   $order                      How to order the tags. Accepts 'ASC' (ascending),
766  *                                                'DESC' (descending), or 'RAND' (random). Default 'ASC'.
767  *     @type int|bool $filter                     Whether to enable filtering of the final output
768  *                                                via {@see 'wp_generate_tag_cloud'}. Default 1|true.
769  *     @type string   $topic_count_text           Nooped plural text from _n_noop() to supply to
770  *                                                tag tooltips. Default null.
771  *     @type callable $topic_count_text_callback  Callback used to generate nooped plural text for
772  *                                                tag tooltips based on the count. Default null.
773  *     @type callable $topic_count_scale_callback Callback used to determine the tag count scaling
774  *                                                value. Default default_topic_count_scale().
775  * }
776  * @return string|array Tag cloud as a string or an array, depending on 'format' argument.
777  */
778 function wp_generate_tag_cloud( $tags, $args = '' ) {
779         $defaults = array(
780                 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 0,
781                 'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC',
782                 'topic_count_text' => null, 'topic_count_text_callback' => null,
783                 'topic_count_scale_callback' => 'default_topic_count_scale', 'filter' => 1,
784         );
785
786         $args = wp_parse_args( $args, $defaults );
787
788         $return = ( 'array' === $args['format'] ) ? array() : '';
789
790         if ( empty( $tags ) ) {
791                 return $return;
792         }
793
794         // Juggle topic count tooltips:
795         if ( isset( $args['topic_count_text'] ) ) {
796                 // First look for nooped plural support via topic_count_text.
797                 $translate_nooped_plural = $args['topic_count_text'];
798         } elseif ( ! empty( $args['topic_count_text_callback'] ) ) {
799                 // Look for the alternative callback style. Ignore the previous default.
800                 if ( $args['topic_count_text_callback'] === 'default_topic_count_text' ) {
801                         $translate_nooped_plural = _n_noop( '%s topic', '%s topics' );
802                 } else {
803                         $translate_nooped_plural = false;
804                 }
805         } elseif ( isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) {
806                 // If no callback exists, look for the old-style single_text and multiple_text arguments.
807                 $translate_nooped_plural = _n_noop( $args['single_text'], $args['multiple_text'] );
808         } else {
809                 // This is the default for when no callback, plural, or argument is passed in.
810                 $translate_nooped_plural = _n_noop( '%s topic', '%s topics' );
811         }
812
813         /**
814          * Filters how the items in a tag cloud are sorted.
815          *
816          * @since 2.8.0
817          *
818          * @param array $tags Ordered array of terms.
819          * @param array $args An array of tag cloud arguments.
820          */
821         $tags_sorted = apply_filters( 'tag_cloud_sort', $tags, $args );
822         if ( empty( $tags_sorted ) ) {
823                 return $return;
824         }
825
826         if ( $tags_sorted !== $tags ) {
827                 $tags = $tags_sorted;
828                 unset( $tags_sorted );
829         } else {
830                 if ( 'RAND' === $args['order'] ) {
831                         shuffle( $tags );
832                 } else {
833                         // SQL cannot save you; this is a second (potentially different) sort on a subset of data.
834                         if ( 'name' === $args['orderby'] ) {
835                                 uasort( $tags, '_wp_object_name_sort_cb' );
836                         } else {
837                                 uasort( $tags, '_wp_object_count_sort_cb' );
838                         }
839
840                         if ( 'DESC' === $args['order'] ) {
841                                 $tags = array_reverse( $tags, true );
842                         }
843                 }
844         }
845
846         if ( $args['number'] > 0 )
847                 $tags = array_slice( $tags, 0, $args['number'] );
848
849         $counts = array();
850         $real_counts = array(); // For the alt tag
851         foreach ( (array) $tags as $key => $tag ) {
852                 $real_counts[ $key ] = $tag->count;
853                 $counts[ $key ] = call_user_func( $args['topic_count_scale_callback'], $tag->count );
854         }
855
856         $min_count = min( $counts );
857         $spread = max( $counts ) - $min_count;
858         if ( $spread <= 0 )
859                 $spread = 1;
860         $font_spread = $args['largest'] - $args['smallest'];
861         if ( $font_spread < 0 )
862                 $font_spread = 1;
863         $font_step = $font_spread / $spread;
864
865         // Assemble the data that will be used to generate the tag cloud markup.
866         $tags_data = array();
867         foreach ( $tags as $key => $tag ) {
868                 $tag_id = isset( $tag->id ) ? $tag->id : $key;
869
870                 $count = $counts[ $key ];
871                 $real_count = $real_counts[ $key ];
872
873                 if ( $translate_nooped_plural ) {
874                         $title = sprintf( translate_nooped_plural( $translate_nooped_plural, $real_count ), number_format_i18n( $real_count ) );
875                 } else {
876                         $title = call_user_func( $args['topic_count_text_callback'], $real_count, $tag, $args );
877                 }
878
879                 $tags_data[] = array(
880                         'id'         => $tag_id,
881                         'url'        => '#' != $tag->link ? $tag->link : '#',
882                         'role'       => '#' != $tag->link ? '' : ' role="button"',
883                         'name'       => $tag->name,
884                         'title'      => $title,
885                         'slug'       => $tag->slug,
886                         'real_count' => $real_count,
887                         'class'      => 'tag-link-' . $tag_id,
888                         'font_size'  => $args['smallest'] + ( $count - $min_count ) * $font_step,
889                 );
890         }
891
892         /**
893          * Filters the data used to generate the tag cloud.
894          *
895          * @since 4.3.0
896          *
897          * @param array $tags_data An array of term data for term used to generate the tag cloud.
898          */
899         $tags_data = apply_filters( 'wp_generate_tag_cloud_data', $tags_data );
900
901         $a = array();
902
903         // generate the output links array
904         foreach ( $tags_data as $key => $tag_data ) {
905                 $class = $tag_data['class'] . ' tag-link-position-' . ( $key + 1 );
906                 $a[] = "<a href='" . esc_url( $tag_data['url'] ) . "'" . $tag_data['role'] . " class='" . esc_attr( $class ) . "' title='" . esc_attr( $tag_data['title'] ) . "' style='font-size: " . esc_attr( str_replace( ',', '.', $tag_data['font_size'] ) . $args['unit'] ) . ";'>" . esc_html( $tag_data['name'] ) . "</a>";
907         }
908
909         switch ( $args['format'] ) {
910                 case 'array' :
911                         $return =& $a;
912                         break;
913                 case 'list' :
914                         $return = "<ul class='wp-tag-cloud'>\n\t<li>";
915                         $return .= join( "</li>\n\t<li>", $a );
916                         $return .= "</li>\n</ul>\n";
917                         break;
918                 default :
919                         $return = join( $args['separator'], $a );
920                         break;
921         }
922
923         if ( $args['filter'] ) {
924                 /**
925                  * Filters the generated output of a tag cloud.
926                  *
927                  * The filter is only evaluated if a true value is passed
928                  * to the $filter argument in wp_generate_tag_cloud().
929                  *
930                  * @since 2.3.0
931                  *
932                  * @see wp_generate_tag_cloud()
933                  *
934                  * @param array|string $return String containing the generated HTML tag cloud output
935                  *                             or an array of tag links if the 'format' argument
936                  *                             equals 'array'.
937                  * @param array        $tags   An array of terms used in the tag cloud.
938                  * @param array        $args   An array of wp_generate_tag_cloud() arguments.
939                  */
940                 return apply_filters( 'wp_generate_tag_cloud', $return, $tags, $args );
941         }
942
943         else
944                 return $return;
945 }
946
947 /**
948  * Serves as a callback for comparing objects based on name.
949  *
950  * Used with `uasort()`.
951  *
952  * @since 3.1.0
953  * @access private
954  *
955  * @param object $a The first object to compare.
956  * @param object $b The second object to compare.
957  * @return int Negative number if `$a->name` is less than `$b->name`, zero if they are equal,
958  *             or greater than zero if `$a->name` is greater than `$b->name`.
959  */
960 function _wp_object_name_sort_cb( $a, $b ) {
961         return strnatcasecmp( $a->name, $b->name );
962 }
963
964 /**
965  * Serves as a callback for comparing objects based on count.
966  *
967  * Used with `uasort()`.
968  *
969  * @since 3.1.0
970  * @access private
971  *
972  * @param object $a The first object to compare.
973  * @param object $b The second object to compare.
974  * @return bool Whether the count value for `$a` is greater than the count value for `$b`.
975  */
976 function _wp_object_count_sort_cb( $a, $b ) {
977         return ( $a->count > $b->count );
978 }
979
980 //
981 // Helper functions
982 //
983
984 /**
985  * Retrieve HTML list content for category list.
986  *
987  * @uses Walker_Category to create HTML list content.
988  * @since 2.1.0
989  * @see Walker_Category::walk() for parameters and return description.
990  * @return string
991  */
992 function walk_category_tree() {
993         $args = func_get_args();
994         // the user's options are the third parameter
995         if ( empty( $args[2]['walker'] ) || ! ( $args[2]['walker'] instanceof Walker ) ) {
996                 $walker = new Walker_Category;
997         } else {
998                 $walker = $args[2]['walker'];
999         }
1000         return call_user_func_array( array( $walker, 'walk' ), $args );
1001 }
1002
1003 /**
1004  * Retrieve HTML dropdown (select) content for category list.
1005  *
1006  * @uses Walker_CategoryDropdown to create HTML dropdown content.
1007  * @since 2.1.0
1008  * @see Walker_CategoryDropdown::walk() for parameters and return description.
1009  * @return string
1010  */
1011 function walk_category_dropdown_tree() {
1012         $args = func_get_args();
1013         // the user's options are the third parameter
1014         if ( empty( $args[2]['walker'] ) || ! ( $args[2]['walker'] instanceof Walker ) ) {
1015                 $walker = new Walker_CategoryDropdown;
1016         } else {
1017                 $walker = $args[2]['walker'];
1018         }
1019         return call_user_func_array( array( $walker, 'walk' ), $args );
1020 }
1021
1022 //
1023 // Tags
1024 //
1025
1026 /**
1027  * Retrieve the link to the tag.
1028  *
1029  * @since 2.3.0
1030  * @see get_term_link()
1031  *
1032  * @param int|object $tag Tag ID or object.
1033  * @return string Link on success, empty string if tag does not exist.
1034  */
1035 function get_tag_link( $tag ) {
1036         if ( ! is_object( $tag ) )
1037                 $tag = (int) $tag;
1038
1039         $tag = get_term_link( $tag, 'post_tag' );
1040
1041         if ( is_wp_error( $tag ) )
1042                 return '';
1043
1044         return $tag;
1045 }
1046
1047 /**
1048  * Retrieve the tags for a post.
1049  *
1050  * @since 2.3.0
1051  *
1052  * @param int $id Post ID.
1053  * @return array|false|WP_Error Array of tag objects on success, false on failure.
1054  */
1055 function get_the_tags( $id = 0 ) {
1056
1057         /**
1058          * Filters the array of tags for the given post.
1059          *
1060          * @since 2.3.0
1061          *
1062          * @see get_the_terms()
1063          *
1064          * @param array $terms An array of tags for the given post.
1065          */
1066         return apply_filters( 'get_the_tags', get_the_terms( $id, 'post_tag' ) );
1067 }
1068
1069 /**
1070  * Retrieve the tags for a post formatted as a string.
1071  *
1072  * @since 2.3.0
1073  *
1074  * @param string $before Optional. Before tags.
1075  * @param string $sep Optional. Between tags.
1076  * @param string $after Optional. After tags.
1077  * @param int $id Optional. Post ID. Defaults to the current post.
1078  * @return string|false|WP_Error A list of tags on success, false if there are no terms, WP_Error on failure.
1079  */
1080 function get_the_tag_list( $before = '', $sep = '', $after = '', $id = 0 ) {
1081
1082         /**
1083          * Filters the tags list for a given post.
1084          *
1085          * @since 2.3.0
1086          *
1087          * @param string $tag_list List of tags.
1088          * @param string $before   String to use before tags.
1089          * @param string $sep      String to use between the tags.
1090          * @param string $after    String to use after tags.
1091          * @param int    $id       Post ID.
1092          */
1093         return apply_filters( 'the_tags', get_the_term_list( $id, 'post_tag', $before, $sep, $after ), $before, $sep, $after, $id );
1094 }
1095
1096 /**
1097  * Retrieve the tags for a post.
1098  *
1099  * @since 2.3.0
1100  *
1101  * @param string $before Optional. Before list.
1102  * @param string $sep Optional. Separate items using this.
1103  * @param string $after Optional. After list.
1104  */
1105 function the_tags( $before = null, $sep = ', ', $after = '' ) {
1106         if ( null === $before )
1107                 $before = __('Tags: ');
1108
1109         $the_tags = get_the_tag_list( $before, $sep, $after );
1110
1111         if ( ! is_wp_error( $the_tags ) ) {
1112                 echo $the_tags;
1113         }
1114 }
1115
1116 /**
1117  * Retrieve tag description.
1118  *
1119  * @since 2.8.0
1120  *
1121  * @param int $tag Optional. Tag ID. Will use global tag ID by default.
1122  * @return string Tag description, available.
1123  */
1124 function tag_description( $tag = 0 ) {
1125         return term_description( $tag );
1126 }
1127
1128 /**
1129  * Retrieve term description.
1130  *
1131  * @since 2.8.0
1132  *
1133  * @param int $term Optional. Term ID. Will use global term ID by default.
1134  * @param string $taxonomy Optional taxonomy name. Defaults to 'post_tag'.
1135  * @return string Term description, available.
1136  */
1137 function term_description( $term = 0, $taxonomy = 'post_tag' ) {
1138         if ( ! $term && ( is_tax() || is_tag() || is_category() ) ) {
1139                 $term = get_queried_object();
1140                 if ( $term ) {
1141                         $taxonomy = $term->taxonomy;
1142                         $term = $term->term_id;
1143                 }
1144         }
1145         $description = get_term_field( 'description', $term, $taxonomy );
1146         return is_wp_error( $description ) ? '' : $description;
1147 }
1148
1149 /**
1150  * Retrieve the terms of the taxonomy that are attached to the post.
1151  *
1152  * @since 2.5.0
1153  *
1154  * @param int|object $post Post ID or object.
1155  * @param string $taxonomy Taxonomy name.
1156  * @return array|false|WP_Error Array of WP_Term objects on success, false if there are no terms
1157  *                              or the post does not exist, WP_Error on failure.
1158  */
1159 function get_the_terms( $post, $taxonomy ) {
1160         if ( ! $post = get_post( $post ) )
1161                 return false;
1162
1163         $terms = get_object_term_cache( $post->ID, $taxonomy );
1164         if ( false === $terms ) {
1165                 $terms = wp_get_object_terms( $post->ID, $taxonomy );
1166                 if ( ! is_wp_error( $terms ) ) {
1167                         $term_ids = wp_list_pluck( $terms, 'term_id' );
1168                         wp_cache_add( $post->ID, $term_ids, $taxonomy . '_relationships' );
1169                 }
1170         }
1171
1172         /**
1173          * Filters the list of terms attached to the given post.
1174          *
1175          * @since 3.1.0
1176          *
1177          * @param array|WP_Error $terms    List of attached terms, or WP_Error on failure.
1178          * @param int            $post_id  Post ID.
1179          * @param string         $taxonomy Name of the taxonomy.
1180          */
1181         $terms = apply_filters( 'get_the_terms', $terms, $post->ID, $taxonomy );
1182
1183         if ( empty( $terms ) )
1184                 return false;
1185
1186         return $terms;
1187 }
1188
1189 /**
1190  * Retrieve a post's terms as a list with specified format.
1191  *
1192  * @since 2.5.0
1193  *
1194  * @param int $id Post ID.
1195  * @param string $taxonomy Taxonomy name.
1196  * @param string $before Optional. Before list.
1197  * @param string $sep Optional. Separate items using this.
1198  * @param string $after Optional. After list.
1199  * @return string|false|WP_Error A list of terms on success, false if there are no terms, WP_Error on failure.
1200  */
1201 function get_the_term_list( $id, $taxonomy, $before = '', $sep = '', $after = '' ) {
1202         $terms = get_the_terms( $id, $taxonomy );
1203
1204         if ( is_wp_error( $terms ) )
1205                 return $terms;
1206
1207         if ( empty( $terms ) )
1208                 return false;
1209
1210         $links = array();
1211
1212         foreach ( $terms as $term ) {
1213                 $link = get_term_link( $term, $taxonomy );
1214                 if ( is_wp_error( $link ) ) {
1215                         return $link;
1216                 }
1217                 $links[] = '<a href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>';
1218         }
1219
1220         /**
1221          * Filters the term links for a given taxonomy.
1222          *
1223          * The dynamic portion of the filter name, `$taxonomy`, refers
1224          * to the taxonomy slug.
1225          *
1226          * @since 2.5.0
1227          *
1228          * @param array $links An array of term links.
1229          */
1230         $term_links = apply_filters( "term_links-{$taxonomy}", $links );
1231
1232         return $before . join( $sep, $term_links ) . $after;
1233 }
1234
1235 /**
1236  * Display the terms in a list.
1237  *
1238  * @since 2.5.0
1239  *
1240  * @param int $id Post ID.
1241  * @param string $taxonomy Taxonomy name.
1242  * @param string $before Optional. Before list.
1243  * @param string $sep Optional. Separate items using this.
1244  * @param string $after Optional. After list.
1245  * @return false|void False on WordPress error.
1246  */
1247 function the_terms( $id, $taxonomy, $before = '', $sep = ', ', $after = '' ) {
1248         $term_list = get_the_term_list( $id, $taxonomy, $before, $sep, $after );
1249
1250         if ( is_wp_error( $term_list ) )
1251                 return false;
1252
1253         /**
1254          * Filters the list of terms to display.
1255          *
1256          * @since 2.9.0
1257          *
1258          * @param array  $term_list List of terms to display.
1259          * @param string $taxonomy  The taxonomy name.
1260          * @param string $before    String to use before the terms.
1261          * @param string $sep       String to use between the terms.
1262          * @param string $after     String to use after the terms.
1263          */
1264         echo apply_filters( 'the_terms', $term_list, $taxonomy, $before, $sep, $after );
1265 }
1266
1267 /**
1268  * Check if the current post has any of given category.
1269  *
1270  * @since 3.1.0
1271  *
1272  * @param string|int|array $category Optional. The category name/term_id/slug or array of them to check for.
1273  * @param int|object $post Optional. Post to check instead of the current post.
1274  * @return bool True if the current post has any of the given categories (or any category, if no category specified).
1275  */
1276 function has_category( $category = '', $post = null ) {
1277         return has_term( $category, 'category', $post );
1278 }
1279
1280 /**
1281  * Check if the current post has any of given tags.
1282  *
1283  * The given tags are checked against the post's tags' term_ids, names and slugs.
1284  * Tags given as integers will only be checked against the post's tags' term_ids.
1285  * If no tags are given, determines if post has any tags.
1286  *
1287  * Prior to v2.7 of WordPress, tags given as integers would also be checked against the post's tags' names and slugs (in addition to term_ids)
1288  * Prior to v2.7, this function could only be used in the WordPress Loop.
1289  * As of 2.7, the function can be used anywhere if it is provided a post ID or post object.
1290  *
1291  * @since 2.6.0
1292  *
1293  * @param string|int|array $tag Optional. The tag name/term_id/slug or array of them to check for.
1294  * @param int|object $post Optional. Post to check instead of the current post. (since 2.7.0)
1295  * @return bool True if the current post has any of the given tags (or any tag, if no tag specified).
1296  */
1297 function has_tag( $tag = '', $post = null ) {
1298         return has_term( $tag, 'post_tag', $post );
1299 }
1300
1301 /**
1302  * Check if the current post has any of given terms.
1303  *
1304  * The given terms are checked against the post's terms' term_ids, names and slugs.
1305  * Terms given as integers will only be checked against the post's terms' term_ids.
1306  * If no terms are given, determines if post has any terms.
1307  *
1308  * @since 3.1.0
1309  *
1310  * @param string|int|array $term Optional. The term name/term_id/slug or array of them to check for.
1311  * @param string $taxonomy Taxonomy name
1312  * @param int|object $post Optional. Post to check instead of the current post.
1313  * @return bool True if the current post has any of the given tags (or any tag, if no tag specified).
1314  */
1315 function has_term( $term = '', $taxonomy = '', $post = null ) {
1316         $post = get_post($post);
1317
1318         if ( !$post )
1319                 return false;
1320
1321         $r = is_object_in_term( $post->ID, $taxonomy, $term );
1322         if ( is_wp_error( $r ) )
1323                 return false;
1324
1325         return $r;
1326 }