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