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