author | Anthony Ly <anthonyly.com@gmail.com> |
Tue, 12 Mar 2013 18:21:39 +0100 | |
changeset 206 | 919b4ddb13fa |
parent 204 | 09a1c134465b |
permissions | -rw-r--r-- |
136 | 1 |
<?php |
2 |
/** |
|
3 |
* WordPress Post Template Functions. |
|
4 |
* |
|
5 |
* Gets content for the current post in the loop. |
|
6 |
* |
|
7 |
* @package WordPress |
|
8 |
* @subpackage Template |
|
9 |
*/ |
|
10 |
||
11 |
/** |
|
12 |
* Display the ID of the current item in the WordPress Loop. |
|
13 |
* |
|
14 |
* @since 0.71 |
|
15 |
*/ |
|
16 |
function the_ID() { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
17 |
echo get_the_ID(); |
136 | 18 |
} |
19 |
||
20 |
/** |
|
21 |
* Retrieve the ID of the current item in the WordPress Loop. |
|
22 |
* |
|
23 |
* @since 2.1.0 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
24 |
* @uses $post |
136 | 25 |
* |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
26 |
* @return int |
136 | 27 |
*/ |
28 |
function get_the_ID() { |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
29 |
return get_post()->ID; |
136 | 30 |
} |
31 |
||
32 |
/** |
|
33 |
* Display or retrieve the current post title with optional content. |
|
34 |
* |
|
35 |
* @since 0.71 |
|
36 |
* |
|
37 |
* @param string $before Optional. Content to prepend to the title. |
|
38 |
* @param string $after Optional. Content to append to the title. |
|
39 |
* @param bool $echo Optional, default to true.Whether to display or return. |
|
40 |
* @return null|string Null on no title. String if $echo parameter is false. |
|
41 |
*/ |
|
42 |
function the_title($before = '', $after = '', $echo = true) { |
|
43 |
$title = get_the_title(); |
|
44 |
||
45 |
if ( strlen($title) == 0 ) |
|
46 |
return; |
|
47 |
||
48 |
$title = $before . $title . $after; |
|
49 |
||
50 |
if ( $echo ) |
|
51 |
echo $title; |
|
52 |
else |
|
53 |
return $title; |
|
54 |
} |
|
55 |
||
56 |
/** |
|
57 |
* Sanitize the current title when retrieving or displaying. |
|
58 |
* |
|
59 |
* Works like {@link the_title()}, except the parameters can be in a string or |
|
60 |
* an array. See the function for what can be override in the $args parameter. |
|
61 |
* |
|
62 |
* The title before it is displayed will have the tags stripped and {@link |
|
63 |
* esc_attr()} before it is passed to the user or displayed. The default |
|
64 |
* as with {@link the_title()}, is to display the title. |
|
65 |
* |
|
66 |
* @since 2.3.0 |
|
67 |
* |
|
68 |
* @param string|array $args Optional. Override the defaults. |
|
69 |
* @return string|null Null on failure or display. String when echo is false. |
|
70 |
*/ |
|
71 |
function the_title_attribute( $args = '' ) { |
|
72 |
$title = get_the_title(); |
|
73 |
||
74 |
if ( strlen($title) == 0 ) |
|
75 |
return; |
|
76 |
||
77 |
$defaults = array('before' => '', 'after' => '', 'echo' => true); |
|
78 |
$r = wp_parse_args($args, $defaults); |
|
79 |
extract( $r, EXTR_SKIP ); |
|
80 |
||
81 |
$title = $before . $title . $after; |
|
82 |
$title = esc_attr(strip_tags($title)); |
|
83 |
||
84 |
if ( $echo ) |
|
85 |
echo $title; |
|
86 |
else |
|
87 |
return $title; |
|
88 |
} |
|
89 |
||
90 |
/** |
|
91 |
* Retrieve post title. |
|
92 |
* |
|
93 |
* If the post is protected and the visitor is not an admin, then "Protected" |
|
94 |
* will be displayed before the post title. If the post is private, then |
|
95 |
* "Private" will be located before the post title. |
|
96 |
* |
|
97 |
* @since 0.71 |
|
98 |
* |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
99 |
* @param mixed $post Optional. Post ID or object. |
136 | 100 |
* @return string |
101 |
*/ |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
102 |
function get_the_title( $post = 0 ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
103 |
$post = get_post( $post ); |
136 | 104 |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
105 |
$title = isset( $post->post_title ) ? $post->post_title : ''; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
106 |
$id = isset( $post->ID ) ? $post->ID : 0; |
136 | 107 |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
108 |
if ( ! is_admin() ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
109 |
if ( ! empty( $post->post_password ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
110 |
$protected_title_format = apply_filters( 'protected_title_format', __( 'Protected: %s' ) ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
111 |
$title = sprintf( $protected_title_format, $title ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
112 |
} else if ( isset( $post->post_status ) && 'private' == $post->post_status ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
113 |
$private_title_format = apply_filters( 'private_title_format', __( 'Private: %s' ) ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
114 |
$title = sprintf( $private_title_format, $title ); |
136 | 115 |
} |
116 |
} |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
117 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
118 |
return apply_filters( 'the_title', $title, $id ); |
136 | 119 |
} |
120 |
||
121 |
/** |
|
122 |
* Display the Post Global Unique Identifier (guid). |
|
123 |
* |
|
124 |
* The guid will appear to be a link, but should not be used as an link to the |
|
125 |
* post. The reason you should not use it as a link, is because of moving the |
|
126 |
* blog across domains. |
|
127 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
128 |
* Url is escaped to make it xml safe |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
129 |
* |
136 | 130 |
* @since 1.5.0 |
131 |
* |
|
132 |
* @param int $id Optional. Post ID. |
|
133 |
*/ |
|
134 |
function the_guid( $id = 0 ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
135 |
echo esc_url( get_the_guid( $id ) ); |
136 | 136 |
} |
137 |
||
138 |
/** |
|
139 |
* Retrieve the Post Global Unique Identifier (guid). |
|
140 |
* |
|
141 |
* The guid will appear to be a link, but should not be used as an link to the |
|
142 |
* post. The reason you should not use it as a link, is because of moving the |
|
143 |
* blog across domains. |
|
144 |
* |
|
145 |
* @since 1.5.0 |
|
146 |
* |
|
147 |
* @param int $id Optional. Post ID. |
|
148 |
* @return string |
|
149 |
*/ |
|
150 |
function get_the_guid( $id = 0 ) { |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
151 |
$post = get_post($id); |
136 | 152 |
|
153 |
return apply_filters('get_the_guid', $post->guid); |
|
154 |
} |
|
155 |
||
156 |
/** |
|
157 |
* Display the post content. |
|
158 |
* |
|
159 |
* @since 0.71 |
|
160 |
* |
|
161 |
* @param string $more_link_text Optional. Content for when there is more text. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
162 |
* @param bool $stripteaser Optional. Strip teaser content before the more text. Default is false. |
136 | 163 |
*/ |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
164 |
function the_content($more_link_text = null, $stripteaser = false) { |
136 | 165 |
$content = get_the_content($more_link_text, $stripteaser); |
166 |
$content = apply_filters('the_content', $content); |
|
167 |
$content = str_replace(']]>', ']]>', $content); |
|
168 |
echo $content; |
|
169 |
} |
|
170 |
||
171 |
/** |
|
172 |
* Retrieve the post content. |
|
173 |
* |
|
174 |
* @since 0.71 |
|
175 |
* |
|
176 |
* @param string $more_link_text Optional. Content for when there is more text. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
177 |
* @param bool $stripteaser Optional. Strip teaser content before the more text. Default is false. |
136 | 178 |
* @return string |
179 |
*/ |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
180 |
function get_the_content( $more_link_text = null, $stripteaser = false ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
181 |
global $more, $page, $pages, $multipage, $preview; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
182 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
183 |
$post = get_post(); |
136 | 184 |
|
185 |
if ( null === $more_link_text ) |
|
186 |
$more_link_text = __( '(more...)' ); |
|
187 |
||
188 |
$output = ''; |
|
189 |
$hasTeaser = false; |
|
190 |
||
191 |
// If post password required and it doesn't match the cookie. |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
192 |
if ( post_password_required() ) |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
193 |
return get_the_password_form(); |
136 | 194 |
|
195 |
if ( $page > count($pages) ) // if the requested page doesn't exist |
|
196 |
$page = count($pages); // give them the highest numbered page that DOES exist |
|
197 |
||
198 |
$content = $pages[$page-1]; |
|
199 |
if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) { |
|
200 |
$content = explode($matches[0], $content, 2); |
|
201 |
if ( !empty($matches[1]) && !empty($more_link_text) ) |
|
202 |
$more_link_text = strip_tags(wp_kses_no_null(trim($matches[1]))); |
|
203 |
||
204 |
$hasTeaser = true; |
|
205 |
} else { |
|
206 |
$content = array($content); |
|
207 |
} |
|
208 |
if ( (false !== strpos($post->post_content, '<!--noteaser-->') && ((!$multipage) || ($page==1))) ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
209 |
$stripteaser = true; |
136 | 210 |
$teaser = $content[0]; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
211 |
if ( $more && $stripteaser && $hasTeaser ) |
136 | 212 |
$teaser = ''; |
213 |
$output .= $teaser; |
|
214 |
if ( count($content) > 1 ) { |
|
215 |
if ( $more ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
216 |
$output .= '<span id="more-' . $post->ID . '"></span>' . $content[1]; |
136 | 217 |
} else { |
218 |
if ( ! empty($more_link_text) ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
219 |
$output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text ); |
136 | 220 |
$output = force_balance_tags($output); |
221 |
} |
|
222 |
||
223 |
} |
|
224 |
if ( $preview ) // preview fix for javascript bug with foreign languages |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
225 |
$output = preg_replace_callback('/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output); |
136 | 226 |
|
227 |
return $output; |
|
228 |
} |
|
229 |
||
230 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
231 |
* Preview fix for javascript bug with foreign languages |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
232 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
233 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
234 |
* @access private |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
235 |
* @param array $match Match array from preg_replace_callback |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
236 |
* @return string |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
237 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
238 |
function _convert_urlencoded_to_entities( $match ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
239 |
return '&#' . base_convert( $match[1], 16, 10 ) . ';'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
240 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
241 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
242 |
/** |
136 | 243 |
* Display the post excerpt. |
244 |
* |
|
245 |
* @since 0.71 |
|
246 |
* @uses apply_filters() Calls 'the_excerpt' hook on post excerpt. |
|
247 |
*/ |
|
248 |
function the_excerpt() { |
|
249 |
echo apply_filters('the_excerpt', get_the_excerpt()); |
|
250 |
} |
|
251 |
||
252 |
/** |
|
253 |
* Retrieve the post excerpt. |
|
254 |
* |
|
255 |
* @since 0.71 |
|
256 |
* |
|
257 |
* @param mixed $deprecated Not used. |
|
258 |
* @return string |
|
259 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
260 |
function get_the_excerpt( $deprecated = '' ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
261 |
if ( !empty( $deprecated ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
262 |
_deprecated_argument( __FUNCTION__, '2.3' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
263 |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
264 |
$post = get_post(); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
265 |
|
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
266 |
if ( post_password_required() ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
267 |
return __( 'There is no excerpt because this is a protected post.' ); |
136 | 268 |
} |
269 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
270 |
return apply_filters( 'get_the_excerpt', $post->post_excerpt ); |
136 | 271 |
} |
272 |
||
273 |
/** |
|
274 |
* Whether post has excerpt. |
|
275 |
* |
|
276 |
* @since 2.3.0 |
|
277 |
* |
|
278 |
* @param int $id Optional. Post ID. |
|
279 |
* @return bool |
|
280 |
*/ |
|
281 |
function has_excerpt( $id = 0 ) { |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
282 |
$post = get_post( $id ); |
136 | 283 |
return ( !empty( $post->post_excerpt ) ); |
284 |
} |
|
285 |
||
286 |
/** |
|
287 |
* Display the classes for the post div. |
|
288 |
* |
|
289 |
* @since 2.7.0 |
|
290 |
* |
|
291 |
* @param string|array $class One or more classes to add to the class list. |
|
292 |
* @param int $post_id An optional post ID. |
|
293 |
*/ |
|
294 |
function post_class( $class = '', $post_id = null ) { |
|
295 |
// Separates classes with a single space, collates classes for post DIV |
|
296 |
echo 'class="' . join( ' ', get_post_class( $class, $post_id ) ) . '"'; |
|
297 |
} |
|
298 |
||
299 |
/** |
|
300 |
* Retrieve the classes for the post div as an array. |
|
301 |
* |
|
302 |
* The class names are add are many. If the post is a sticky, then the 'sticky' |
|
303 |
* class name. The class 'hentry' is always added to each post. For each |
|
304 |
* category, the class will be added with 'category-' with category slug is |
|
305 |
* added. The tags are the same way as the categories with 'tag-' before the tag |
|
306 |
* slug. All classes are passed through the filter, 'post_class' with the list |
|
307 |
* of classes, followed by $class parameter value, with the post ID as the last |
|
308 |
* parameter. |
|
309 |
* |
|
310 |
* @since 2.7.0 |
|
311 |
* |
|
312 |
* @param string|array $class One or more classes to add to the class list. |
|
313 |
* @param int $post_id An optional post ID. |
|
314 |
* @return array Array of classes. |
|
315 |
*/ |
|
316 |
function get_post_class( $class = '', $post_id = null ) { |
|
317 |
$post = get_post($post_id); |
|
318 |
||
319 |
$classes = array(); |
|
320 |
||
321 |
if ( empty($post) ) |
|
322 |
return $classes; |
|
323 |
||
324 |
$classes[] = 'post-' . $post->ID; |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
325 |
if ( ! is_admin() ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
326 |
$classes[] = $post->post_type; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
327 |
$classes[] = 'type-' . $post->post_type; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
328 |
$classes[] = 'status-' . $post->post_status; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
329 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
330 |
// Post Format |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
331 |
if ( post_type_supports( $post->post_type, 'post-formats' ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
332 |
$post_format = get_post_format( $post->ID ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
333 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
334 |
if ( $post_format && !is_wp_error($post_format) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
335 |
$classes[] = 'format-' . sanitize_html_class( $post_format ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
336 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
337 |
$classes[] = 'format-standard'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
338 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
339 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
340 |
// post requires password |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
341 |
if ( post_password_required($post->ID) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
342 |
$classes[] = 'post-password-required'; |
136 | 343 |
|
344 |
// sticky for Sticky Posts |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
345 |
if ( is_sticky($post->ID) && is_home() && !is_paged() ) |
136 | 346 |
$classes[] = 'sticky'; |
347 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
348 |
// hentry for hAtom compliance |
136 | 349 |
$classes[] = 'hentry'; |
350 |
||
351 |
// Categories |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
352 |
if ( is_object_in_taxonomy( $post->post_type, 'category' ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
353 |
foreach ( (array) get_the_category($post->ID) as $cat ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
354 |
if ( empty($cat->slug ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
355 |
continue; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
356 |
$classes[] = 'category-' . sanitize_html_class($cat->slug, $cat->term_id); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
357 |
} |
136 | 358 |
} |
359 |
||
360 |
// Tags |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
361 |
if ( is_object_in_taxonomy( $post->post_type, 'post_tag' ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
362 |
foreach ( (array) get_the_tags($post->ID) as $tag ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
363 |
if ( empty($tag->slug ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
364 |
continue; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
365 |
$classes[] = 'tag-' . sanitize_html_class($tag->slug, $tag->term_id); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
366 |
} |
136 | 367 |
} |
368 |
||
369 |
if ( !empty($class) ) { |
|
370 |
if ( !is_array( $class ) ) |
|
371 |
$class = preg_split('#\s+#', $class); |
|
372 |
$classes = array_merge($classes, $class); |
|
373 |
} |
|
374 |
||
375 |
$classes = array_map('esc_attr', $classes); |
|
376 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
377 |
return apply_filters('post_class', $classes, $class, $post->ID); |
136 | 378 |
} |
379 |
||
380 |
/** |
|
381 |
* Display the classes for the body element. |
|
382 |
* |
|
383 |
* @since 2.8.0 |
|
384 |
* |
|
385 |
* @param string|array $class One or more classes to add to the class list. |
|
386 |
*/ |
|
387 |
function body_class( $class = '' ) { |
|
388 |
// Separates classes with a single space, collates classes for body element |
|
389 |
echo 'class="' . join( ' ', get_body_class( $class ) ) . '"'; |
|
390 |
} |
|
391 |
||
392 |
/** |
|
393 |
* Retrieve the classes for the body element as an array. |
|
394 |
* |
|
395 |
* @since 2.8.0 |
|
396 |
* |
|
397 |
* @param string|array $class One or more classes to add to the class list. |
|
398 |
* @return array Array of classes. |
|
399 |
*/ |
|
400 |
function get_body_class( $class = '' ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
401 |
global $wp_query, $wpdb; |
136 | 402 |
|
403 |
$classes = array(); |
|
404 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
405 |
if ( is_rtl() ) |
136 | 406 |
$classes[] = 'rtl'; |
407 |
||
408 |
if ( is_front_page() ) |
|
409 |
$classes[] = 'home'; |
|
410 |
if ( is_home() ) |
|
411 |
$classes[] = 'blog'; |
|
412 |
if ( is_archive() ) |
|
413 |
$classes[] = 'archive'; |
|
414 |
if ( is_date() ) |
|
415 |
$classes[] = 'date'; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
416 |
if ( is_search() ) { |
136 | 417 |
$classes[] = 'search'; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
418 |
$classes[] = $wp_query->posts ? 'search-results' : 'search-no-results'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
419 |
} |
136 | 420 |
if ( is_paged() ) |
421 |
$classes[] = 'paged'; |
|
422 |
if ( is_attachment() ) |
|
423 |
$classes[] = 'attachment'; |
|
424 |
if ( is_404() ) |
|
425 |
$classes[] = 'error404'; |
|
426 |
||
427 |
if ( is_single() ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
428 |
$post_id = $wp_query->get_queried_object_id(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
429 |
$post = $wp_query->get_queried_object(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
430 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
431 |
$classes[] = 'single'; |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
432 |
if ( isset( $post->post_type ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
433 |
$classes[] = 'single-' . sanitize_html_class($post->post_type, $post_id); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
434 |
$classes[] = 'postid-' . $post_id; |
136 | 435 |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
436 |
// Post Format |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
437 |
if ( post_type_supports( $post->post_type, 'post-formats' ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
438 |
$post_format = get_post_format( $post->ID ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
439 |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
440 |
if ( $post_format && !is_wp_error($post_format) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
441 |
$classes[] = 'single-format-' . sanitize_html_class( $post_format ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
442 |
else |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
443 |
$classes[] = 'single-format-standard'; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
444 |
} |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
445 |
} |
136 | 446 |
|
447 |
if ( is_attachment() ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
448 |
$mime_type = get_post_mime_type($post_id); |
136 | 449 |
$mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
450 |
$classes[] = 'attachmentid-' . $post_id; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
451 |
$classes[] = 'attachment-' . str_replace( $mime_prefix, '', $mime_type ); |
136 | 452 |
} |
453 |
} elseif ( is_archive() ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
454 |
if ( is_post_type_archive() ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
455 |
$classes[] = 'post-type-archive'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
456 |
$classes[] = 'post-type-archive-' . sanitize_html_class( get_query_var( 'post_type' ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
457 |
} else if ( is_author() ) { |
136 | 458 |
$author = $wp_query->get_queried_object(); |
459 |
$classes[] = 'author'; |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
460 |
if ( isset( $author->user_nicename ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
461 |
$classes[] = 'author-' . sanitize_html_class( $author->user_nicename, $author->ID ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
462 |
$classes[] = 'author-' . $author->ID; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
463 |
} |
136 | 464 |
} elseif ( is_category() ) { |
465 |
$cat = $wp_query->get_queried_object(); |
|
466 |
$classes[] = 'category'; |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
467 |
if ( isset( $cat->term_id ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
468 |
$classes[] = 'category-' . sanitize_html_class( $cat->slug, $cat->term_id ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
469 |
$classes[] = 'category-' . $cat->term_id; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
470 |
} |
136 | 471 |
} elseif ( is_tag() ) { |
472 |
$tags = $wp_query->get_queried_object(); |
|
473 |
$classes[] = 'tag'; |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
474 |
if ( isset( $tags->term_id ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
475 |
$classes[] = 'tag-' . sanitize_html_class( $tags->slug, $tags->term_id ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
476 |
$classes[] = 'tag-' . $tags->term_id; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
477 |
} |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
478 |
} elseif ( is_tax() ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
479 |
$term = $wp_query->get_queried_object(); |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
480 |
if ( isset( $term->term_id ) ) { |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
481 |
$classes[] = 'tax-' . sanitize_html_class( $term->taxonomy ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
482 |
$classes[] = 'term-' . sanitize_html_class( $term->slug, $term->term_id ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
483 |
$classes[] = 'term-' . $term->term_id; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
484 |
} |
136 | 485 |
} |
486 |
} elseif ( is_page() ) { |
|
487 |
$classes[] = 'page'; |
|
488 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
489 |
$page_id = $wp_query->get_queried_object_id(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
490 |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
491 |
$post = get_post($page_id); |
136 | 492 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
493 |
$classes[] = 'page-id-' . $page_id; |
136 | 494 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
495 |
if ( $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status = 'publish' LIMIT 1", $page_id) ) ) |
136 | 496 |
$classes[] = 'page-parent'; |
497 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
498 |
if ( $post->post_parent ) { |
136 | 499 |
$classes[] = 'page-child'; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
500 |
$classes[] = 'parent-pageid-' . $post->post_parent; |
136 | 501 |
} |
502 |
if ( is_page_template() ) { |
|
503 |
$classes[] = 'page-template'; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
504 |
$classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', get_page_template_slug( $page_id ) ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
505 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
506 |
$classes[] = 'page-template-default'; |
136 | 507 |
} |
508 |
} |
|
509 |
||
510 |
if ( is_user_logged_in() ) |
|
511 |
$classes[] = 'logged-in'; |
|
512 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
513 |
if ( is_admin_bar_showing() ) { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
514 |
$classes[] = 'admin-bar'; |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
515 |
$classes[] = 'no-customize-support'; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
516 |
} |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
517 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
518 |
if ( get_theme_mod( 'background_color' ) || get_background_image() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
519 |
$classes[] = 'custom-background'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
520 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
521 |
$page = $wp_query->get( 'page' ); |
136 | 522 |
|
523 |
if ( !$page || $page < 2) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
524 |
$page = $wp_query->get( 'paged' ); |
136 | 525 |
|
526 |
if ( $page && $page > 1 ) { |
|
527 |
$classes[] = 'paged-' . $page; |
|
528 |
||
529 |
if ( is_single() ) |
|
530 |
$classes[] = 'single-paged-' . $page; |
|
531 |
elseif ( is_page() ) |
|
532 |
$classes[] = 'page-paged-' . $page; |
|
533 |
elseif ( is_category() ) |
|
534 |
$classes[] = 'category-paged-' . $page; |
|
535 |
elseif ( is_tag() ) |
|
536 |
$classes[] = 'tag-paged-' . $page; |
|
537 |
elseif ( is_date() ) |
|
538 |
$classes[] = 'date-paged-' . $page; |
|
539 |
elseif ( is_author() ) |
|
540 |
$classes[] = 'author-paged-' . $page; |
|
541 |
elseif ( is_search() ) |
|
542 |
$classes[] = 'search-paged-' . $page; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
543 |
elseif ( is_post_type_archive() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
544 |
$classes[] = 'post-type-paged-' . $page; |
136 | 545 |
} |
546 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
547 |
if ( ! empty( $class ) ) { |
136 | 548 |
if ( !is_array( $class ) ) |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
549 |
$class = preg_split( '#\s+#', $class ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
550 |
$classes = array_merge( $classes, $class ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
551 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
552 |
// Ensure that we always coerce class to being an array. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
553 |
$class = array(); |
136 | 554 |
} |
555 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
556 |
$classes = array_map( 'esc_attr', $classes ); |
136 | 557 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
558 |
return apply_filters( 'body_class', $classes, $class ); |
136 | 559 |
} |
560 |
||
561 |
/** |
|
562 |
* Whether post requires password and correct password has been provided. |
|
563 |
* |
|
564 |
* @since 2.7.0 |
|
565 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
566 |
* @param int|object $post An optional post. Global $post used if not provided. |
136 | 567 |
* @return bool false if a password is not required or the correct password cookie is present, true otherwise. |
568 |
*/ |
|
569 |
function post_password_required( $post = null ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
570 |
global $wp_hasher; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
571 |
|
136 | 572 |
$post = get_post($post); |
573 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
574 |
if ( empty( $post->post_password ) ) |
136 | 575 |
return false; |
576 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
577 |
if ( ! isset( $_COOKIE['wp-postpass_' . COOKIEHASH] ) ) |
136 | 578 |
return true; |
579 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
580 |
if ( empty( $wp_hasher ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
581 |
require_once( ABSPATH . 'wp-includes/class-phpass.php'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
582 |
// By default, use the portable hash from phpass |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
583 |
$wp_hasher = new PasswordHash(8, true); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
584 |
} |
136 | 585 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
586 |
$hash = stripslashes( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
587 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
588 |
return ! $wp_hasher->CheckPassword( $post->post_password, $hash ); |
136 | 589 |
} |
590 |
||
591 |
/** |
|
592 |
* Page Template Functions for usage in Themes |
|
593 |
* |
|
594 |
* @package WordPress |
|
595 |
* @subpackage Template |
|
596 |
*/ |
|
597 |
||
598 |
/** |
|
599 |
* The formatted output of a list of pages. |
|
600 |
* |
|
601 |
* Displays page links for paginated posts (i.e. includes the <!--nextpage-->. |
|
602 |
* Quicktag one or more times). This tag must be within The Loop. |
|
603 |
* |
|
604 |
* The defaults for overwriting are: |
|
605 |
* 'next_or_number' - Default is 'number' (string). Indicates whether page |
|
606 |
* numbers should be used. Valid values are number and next. |
|
607 |
* 'nextpagelink' - Default is 'Next Page' (string). Text for link to next page. |
|
608 |
* of the bookmark. |
|
609 |
* 'previouspagelink' - Default is 'Previous Page' (string). Text for link to |
|
610 |
* previous page, if available. |
|
611 |
* 'pagelink' - Default is '%' (String).Format string for page numbers. The % in |
|
612 |
* the parameter string will be replaced with the page number, so Page % |
|
613 |
* generates "Page 1", "Page 2", etc. Defaults to %, just the page number. |
|
614 |
* 'before' - Default is '<p> Pages:' (string). The html or text to prepend to |
|
615 |
* each bookmarks. |
|
616 |
* 'after' - Default is '</p>' (string). The html or text to append to each |
|
617 |
* bookmarks. |
|
618 |
* 'link_before' - Default is '' (string). The html or text to prepend to each |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
619 |
* Pages link inside the <a> tag. Also prepended to the current item, which |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
620 |
* is not linked. |
136 | 621 |
* 'link_after' - Default is '' (string). The html or text to append to each |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
622 |
* Pages link inside the <a> tag. Also appended to the current item, which |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
623 |
* is not linked. |
136 | 624 |
* |
625 |
* @since 1.2.0 |
|
626 |
* @access private |
|
627 |
* |
|
628 |
* @param string|array $args Optional. Overwrite the defaults. |
|
629 |
* @return string Formatted output in HTML. |
|
630 |
*/ |
|
631 |
function wp_link_pages($args = '') { |
|
632 |
$defaults = array( |
|
633 |
'before' => '<p>' . __('Pages:'), 'after' => '</p>', |
|
634 |
'link_before' => '', 'link_after' => '', |
|
635 |
'next_or_number' => 'number', 'nextpagelink' => __('Next page'), |
|
636 |
'previouspagelink' => __('Previous page'), 'pagelink' => '%', |
|
637 |
'echo' => 1 |
|
638 |
); |
|
639 |
||
640 |
$r = wp_parse_args( $args, $defaults ); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
641 |
$r = apply_filters( 'wp_link_pages_args', $r ); |
136 | 642 |
extract( $r, EXTR_SKIP ); |
643 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
644 |
global $page, $numpages, $multipage, $more, $pagenow; |
136 | 645 |
|
646 |
$output = ''; |
|
647 |
if ( $multipage ) { |
|
648 |
if ( 'number' == $next_or_number ) { |
|
649 |
$output .= $before; |
|
650 |
for ( $i = 1; $i < ($numpages+1); $i = $i + 1 ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
651 |
$j = str_replace('%',$i,$pagelink); |
136 | 652 |
$output .= ' '; |
653 |
if ( ($i != $page) || ((!$more) && ($page==1)) ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
654 |
$output .= _wp_link_page($i); |
136 | 655 |
} |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
656 |
$output .= $link_before . $j . $link_after; |
136 | 657 |
if ( ($i != $page) || ((!$more) && ($page==1)) ) |
658 |
$output .= '</a>'; |
|
659 |
} |
|
660 |
$output .= $after; |
|
661 |
} else { |
|
662 |
if ( $more ) { |
|
663 |
$output .= $before; |
|
664 |
$i = $page - 1; |
|
665 |
if ( $i && $more ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
666 |
$output .= _wp_link_page($i); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
667 |
$output .= $link_before. $previouspagelink . $link_after . '</a>'; |
136 | 668 |
} |
669 |
$i = $page + 1; |
|
670 |
if ( $i <= $numpages && $more ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
671 |
$output .= _wp_link_page($i); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
672 |
$output .= $link_before. $nextpagelink . $link_after . '</a>'; |
136 | 673 |
} |
674 |
$output .= $after; |
|
675 |
} |
|
676 |
} |
|
677 |
} |
|
678 |
||
679 |
if ( $echo ) |
|
680 |
echo $output; |
|
681 |
||
682 |
return $output; |
|
683 |
} |
|
684 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
685 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
686 |
* Helper function for wp_link_pages(). |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
687 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
688 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
689 |
* @access private |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
690 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
691 |
* @param int $i Page number. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
692 |
* @return string Link. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
693 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
694 |
function _wp_link_page( $i ) { |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
695 |
global $wp_rewrite; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
696 |
$post = get_post(); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
697 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
698 |
if ( 1 == $i ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
699 |
$url = get_permalink(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
700 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
701 |
if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
702 |
$url = add_query_arg( 'page', $i, get_permalink() ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
703 |
elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
704 |
$url = trailingslashit(get_permalink()) . user_trailingslashit("$wp_rewrite->pagination_base/" . $i, 'single_paged'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
705 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
706 |
$url = trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged'); |
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 |
return '<a href="' . esc_url( $url ) . '">'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
710 |
} |
136 | 711 |
|
712 |
// |
|
713 |
// Post-meta: Custom per-post fields. |
|
714 |
// |
|
715 |
||
716 |
/** |
|
717 |
* Retrieve post custom meta data field. |
|
718 |
* |
|
719 |
* @since 1.5.0 |
|
720 |
* |
|
721 |
* @param string $key Meta data key name. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
722 |
* @return bool|string|array Array of values or single value, if only one element exists. False will be returned if key does not exist. |
136 | 723 |
*/ |
724 |
function post_custom( $key = '' ) { |
|
725 |
$custom = get_post_custom(); |
|
726 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
727 |
if ( !isset( $custom[$key] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
728 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
729 |
elseif ( 1 == count($custom[$key]) ) |
136 | 730 |
return $custom[$key][0]; |
731 |
else |
|
732 |
return $custom[$key]; |
|
733 |
} |
|
734 |
||
735 |
/** |
|
736 |
* Display list of post custom fields. |
|
737 |
* |
|
738 |
* @internal This will probably change at some point... |
|
739 |
* @since 1.2.0 |
|
740 |
* @uses apply_filters() Calls 'the_meta_key' on list item HTML content, with key and value as separate parameters. |
|
741 |
*/ |
|
742 |
function the_meta() { |
|
743 |
if ( $keys = get_post_custom_keys() ) { |
|
744 |
echo "<ul class='post-meta'>\n"; |
|
745 |
foreach ( (array) $keys as $key ) { |
|
746 |
$keyt = trim($key); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
747 |
if ( is_protected_meta( $keyt, 'post' ) ) |
136 | 748 |
continue; |
749 |
$values = array_map('trim', get_post_custom_values($key)); |
|
750 |
$value = implode($values,', '); |
|
751 |
echo apply_filters('the_meta_key', "<li><span class='post-meta-key'>$key:</span> $value</li>\n", $key, $value); |
|
752 |
} |
|
753 |
echo "</ul>\n"; |
|
754 |
} |
|
755 |
} |
|
756 |
||
757 |
// |
|
758 |
// Pages |
|
759 |
// |
|
760 |
||
761 |
/** |
|
762 |
* Retrieve or display list of pages as a dropdown (select list). |
|
763 |
* |
|
764 |
* @since 2.1.0 |
|
765 |
* |
|
766 |
* @param array|string $args Optional. Override default arguments. |
|
767 |
* @return string HTML content, if not displaying. |
|
768 |
*/ |
|
769 |
function wp_dropdown_pages($args = '') { |
|
770 |
$defaults = array( |
|
771 |
'depth' => 0, 'child_of' => 0, |
|
772 |
'selected' => 0, 'echo' => 1, |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
773 |
'name' => 'page_id', 'id' => '', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
774 |
'show_option_none' => '', 'show_option_no_change' => '', |
136 | 775 |
'option_none_value' => '' |
776 |
); |
|
777 |
||
778 |
$r = wp_parse_args( $args, $defaults ); |
|
779 |
extract( $r, EXTR_SKIP ); |
|
780 |
||
781 |
$pages = get_pages($r); |
|
782 |
$output = ''; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
783 |
// Back-compat with old system where both id and name were based on $name argument |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
784 |
if ( empty($id) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
785 |
$id = $name; |
136 | 786 |
|
787 |
if ( ! empty($pages) ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
788 |
$output = "<select name='" . esc_attr( $name ) . "' id='" . esc_attr( $id ) . "'>\n"; |
136 | 789 |
if ( $show_option_no_change ) |
790 |
$output .= "\t<option value=\"-1\">$show_option_no_change</option>"; |
|
791 |
if ( $show_option_none ) |
|
792 |
$output .= "\t<option value=\"" . esc_attr($option_none_value) . "\">$show_option_none</option>\n"; |
|
793 |
$output .= walk_page_dropdown_tree($pages, $depth, $r); |
|
794 |
$output .= "</select>\n"; |
|
795 |
} |
|
796 |
||
797 |
$output = apply_filters('wp_dropdown_pages', $output); |
|
798 |
||
799 |
if ( $echo ) |
|
800 |
echo $output; |
|
801 |
||
802 |
return $output; |
|
803 |
} |
|
804 |
||
805 |
/** |
|
806 |
* Retrieve or display list of pages in list (li) format. |
|
807 |
* |
|
808 |
* @since 1.5.0 |
|
809 |
* |
|
810 |
* @param array|string $args Optional. Override default arguments. |
|
811 |
* @return string HTML content, if not displaying. |
|
812 |
*/ |
|
813 |
function wp_list_pages($args = '') { |
|
814 |
$defaults = array( |
|
815 |
'depth' => 0, 'show_date' => '', |
|
816 |
'date_format' => get_option('date_format'), |
|
817 |
'child_of' => 0, 'exclude' => '', |
|
818 |
'title_li' => __('Pages'), 'echo' => 1, |
|
819 |
'authors' => '', 'sort_column' => 'menu_order, post_title', |
|
820 |
'link_before' => '', 'link_after' => '', 'walker' => '', |
|
821 |
); |
|
822 |
||
823 |
$r = wp_parse_args( $args, $defaults ); |
|
824 |
extract( $r, EXTR_SKIP ); |
|
825 |
||
826 |
$output = ''; |
|
827 |
$current_page = 0; |
|
828 |
||
829 |
// sanitize, mostly to keep spaces out |
|
830 |
$r['exclude'] = preg_replace('/[^0-9,]/', '', $r['exclude']); |
|
831 |
||
832 |
// Allow plugins to filter an array of excluded pages (but don't put a nullstring into the array) |
|
833 |
$exclude_array = ( $r['exclude'] ) ? explode(',', $r['exclude']) : array(); |
|
834 |
$r['exclude'] = implode( ',', apply_filters('wp_list_pages_excludes', $exclude_array) ); |
|
835 |
||
836 |
// Query pages. |
|
837 |
$r['hierarchical'] = 0; |
|
838 |
$pages = get_pages($r); |
|
839 |
||
840 |
if ( !empty($pages) ) { |
|
841 |
if ( $r['title_li'] ) |
|
842 |
$output .= '<li class="pagenav">' . $r['title_li'] . '<ul>'; |
|
843 |
||
844 |
global $wp_query; |
|
845 |
if ( is_page() || is_attachment() || $wp_query->is_posts_page ) |
|
846 |
$current_page = $wp_query->get_queried_object_id(); |
|
847 |
$output .= walk_page_tree($pages, $r['depth'], $current_page, $r); |
|
848 |
||
849 |
if ( $r['title_li'] ) |
|
850 |
$output .= '</ul></li>'; |
|
851 |
} |
|
852 |
||
853 |
$output = apply_filters('wp_list_pages', $output, $r); |
|
854 |
||
855 |
if ( $r['echo'] ) |
|
856 |
echo $output; |
|
857 |
else |
|
858 |
return $output; |
|
859 |
} |
|
860 |
||
861 |
/** |
|
862 |
* Display or retrieve list of pages with optional home link. |
|
863 |
* |
|
864 |
* The arguments are listed below and part of the arguments are for {@link |
|
865 |
* wp_list_pages()} function. Check that function for more info on those |
|
866 |
* arguments. |
|
867 |
* |
|
868 |
* <ul> |
|
869 |
* <li><strong>sort_column</strong> - How to sort the list of pages. Defaults |
|
870 |
* to page title. Use column for posts table.</li> |
|
871 |
* <li><strong>menu_class</strong> - Class to use for the div ID which contains |
|
872 |
* the page list. Defaults to 'menu'.</li> |
|
873 |
* <li><strong>echo</strong> - Whether to echo list or return it. Defaults to |
|
874 |
* echo.</li> |
|
875 |
* <li><strong>link_before</strong> - Text before show_home argument text.</li> |
|
876 |
* <li><strong>link_after</strong> - Text after show_home argument text.</li> |
|
877 |
* <li><strong>show_home</strong> - If you set this argument, then it will |
|
878 |
* display the link to the home page. The show_home argument really just needs |
|
879 |
* to be set to the value of the text of the link.</li> |
|
880 |
* </ul> |
|
881 |
* |
|
882 |
* @since 2.7.0 |
|
883 |
* |
|
884 |
* @param array|string $args |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
885 |
* @return string html menu |
136 | 886 |
*/ |
887 |
function wp_page_menu( $args = array() ) { |
|
888 |
$defaults = array('sort_column' => 'menu_order, post_title', 'menu_class' => 'menu', 'echo' => true, 'link_before' => '', 'link_after' => ''); |
|
889 |
$args = wp_parse_args( $args, $defaults ); |
|
890 |
$args = apply_filters( 'wp_page_menu_args', $args ); |
|
891 |
||
892 |
$menu = ''; |
|
893 |
||
894 |
$list_args = $args; |
|
895 |
||
896 |
// Show Home in the menu |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
897 |
if ( ! empty($args['show_home']) ) { |
136 | 898 |
if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] ) |
899 |
$text = __('Home'); |
|
900 |
else |
|
901 |
$text = $args['show_home']; |
|
902 |
$class = ''; |
|
903 |
if ( is_front_page() && !is_paged() ) |
|
904 |
$class = 'class="current_page_item"'; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
905 |
$menu .= '<li ' . $class . '><a href="' . home_url( '/' ) . '" title="' . esc_attr($text) . '">' . $args['link_before'] . $text . $args['link_after'] . '</a></li>'; |
136 | 906 |
// If the front page is a page, add it to the exclude list |
907 |
if (get_option('show_on_front') == 'page') { |
|
908 |
if ( !empty( $list_args['exclude'] ) ) { |
|
909 |
$list_args['exclude'] .= ','; |
|
910 |
} else { |
|
911 |
$list_args['exclude'] = ''; |
|
912 |
} |
|
913 |
$list_args['exclude'] .= get_option('page_on_front'); |
|
914 |
} |
|
915 |
} |
|
916 |
||
917 |
$list_args['echo'] = false; |
|
918 |
$list_args['title_li'] = ''; |
|
919 |
$menu .= str_replace( array( "\r", "\n", "\t" ), '', wp_list_pages($list_args) ); |
|
920 |
||
921 |
if ( $menu ) |
|
922 |
$menu = '<ul>' . $menu . '</ul>'; |
|
923 |
||
924 |
$menu = '<div class="' . esc_attr($args['menu_class']) . '">' . $menu . "</div>\n"; |
|
925 |
$menu = apply_filters( 'wp_page_menu', $menu, $args ); |
|
926 |
if ( $args['echo'] ) |
|
927 |
echo $menu; |
|
928 |
else |
|
929 |
return $menu; |
|
930 |
} |
|
931 |
||
932 |
// |
|
933 |
// Page helpers |
|
934 |
// |
|
935 |
||
936 |
/** |
|
937 |
* Retrieve HTML list content for page list. |
|
938 |
* |
|
939 |
* @uses Walker_Page to create HTML list content. |
|
940 |
* @since 2.1.0 |
|
941 |
* @see Walker_Page::walk() for parameters and return description. |
|
942 |
*/ |
|
943 |
function walk_page_tree($pages, $depth, $current_page, $r) { |
|
944 |
if ( empty($r['walker']) ) |
|
945 |
$walker = new Walker_Page; |
|
946 |
else |
|
947 |
$walker = $r['walker']; |
|
948 |
||
949 |
$args = array($pages, $depth, $r, $current_page); |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
950 |
return call_user_func_array(array($walker, 'walk'), $args); |
136 | 951 |
} |
952 |
||
953 |
/** |
|
954 |
* Retrieve HTML dropdown (select) content for page list. |
|
955 |
* |
|
956 |
* @uses Walker_PageDropdown to create HTML dropdown content. |
|
957 |
* @since 2.1.0 |
|
958 |
* @see Walker_PageDropdown::walk() for parameters and return description. |
|
959 |
*/ |
|
960 |
function walk_page_dropdown_tree() { |
|
961 |
$args = func_get_args(); |
|
962 |
if ( empty($args[2]['walker']) ) // the user's options are the third parameter |
|
963 |
$walker = new Walker_PageDropdown; |
|
964 |
else |
|
965 |
$walker = $args[2]['walker']; |
|
966 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
967 |
return call_user_func_array(array($walker, 'walk'), $args); |
136 | 968 |
} |
969 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
970 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
971 |
* Create HTML list of pages. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
972 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
973 |
* @package WordPress |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
974 |
* @since 2.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
975 |
* @uses Walker |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
976 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
977 |
class Walker_Page extends Walker { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
978 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
979 |
* @see Walker::$tree_type |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
980 |
* @since 2.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
981 |
* @var string |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
982 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
983 |
var $tree_type = 'page'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
984 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
985 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
986 |
* @see Walker::$db_fields |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
987 |
* @since 2.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
988 |
* @todo Decouple this. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
989 |
* @var array |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
990 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
991 |
var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
992 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
993 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
994 |
* @see Walker::start_lvl() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
995 |
* @since 2.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
996 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
997 |
* @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
|
998 |
* @param int $depth Depth of page. Used for padding. |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
999 |
* @param array $args |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1000 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1001 |
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
|
1002 |
$indent = str_repeat("\t", $depth); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1003 |
$output .= "\n$indent<ul class='children'>\n"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1004 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1005 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1006 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1007 |
* @see Walker::end_lvl() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1008 |
* @since 2.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1009 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1010 |
* @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
|
1011 |
* @param int $depth Depth of page. Used for padding. |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1012 |
* @param array $args |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1013 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1014 |
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
|
1015 |
$indent = str_repeat("\t", $depth); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1016 |
$output .= "$indent</ul>\n"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1017 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1018 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1019 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1020 |
* @see Walker::start_el() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1021 |
* @since 2.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1022 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1023 |
* @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
|
1024 |
* @param object $page Page data object. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1025 |
* @param int $depth Depth of page. Used for padding. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1026 |
* @param int $current_page Page ID. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1027 |
* @param array $args |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1028 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1029 |
function start_el( &$output, $page, $depth, $args, $current_page = 0 ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1030 |
if ( $depth ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1031 |
$indent = str_repeat("\t", $depth); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1032 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1033 |
$indent = ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1034 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1035 |
extract($args, EXTR_SKIP); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1036 |
$css_class = array('page_item', 'page-item-'.$page->ID); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1037 |
if ( !empty($current_page) ) { |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1038 |
$_current_page = get_post( $current_page ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1039 |
if ( in_array( $page->ID, $_current_page->ancestors ) ) |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1040 |
$css_class[] = 'current_page_ancestor'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1041 |
if ( $page->ID == $current_page ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1042 |
$css_class[] = 'current_page_item'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1043 |
elseif ( $_current_page && $page->ID == $_current_page->post_parent ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1044 |
$css_class[] = 'current_page_parent'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1045 |
} elseif ( $page->ID == get_option('page_for_posts') ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1046 |
$css_class[] = 'current_page_parent'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1047 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1048 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1049 |
$css_class = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1050 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1051 |
$output .= $indent . '<li class="' . $css_class . '"><a href="' . get_permalink($page->ID) . '">' . $link_before . apply_filters( 'the_title', $page->post_title, $page->ID ) . $link_after . '</a>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1052 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1053 |
if ( !empty($show_date) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1054 |
if ( 'modified' == $show_date ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1055 |
$time = $page->post_modified; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1056 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1057 |
$time = $page->post_date; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1058 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1059 |
$output .= " " . mysql2date($date_format, $time); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1060 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1061 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1062 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1063 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1064 |
* @see Walker::end_el() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1065 |
* @since 2.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1066 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1067 |
* @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
|
1068 |
* @param object $page Page data object. Not used. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1069 |
* @param int $depth Depth of page. Not Used. |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1070 |
* @param array $args |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1071 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1072 |
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
|
1073 |
$output .= "</li>\n"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1074 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1075 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1076 |
} |
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 |
* Create HTML dropdown list of pages. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1080 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1081 |
* @package WordPress |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1082 |
* @since 2.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1083 |
* @uses Walker |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1084 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1085 |
class Walker_PageDropdown extends Walker { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1086 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1087 |
* @see Walker::$tree_type |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1088 |
* @since 2.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1089 |
* @var string |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1090 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1091 |
var $tree_type = 'page'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1092 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1093 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1094 |
* @see Walker::$db_fields |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1095 |
* @since 2.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1096 |
* @todo Decouple this |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1097 |
* @var array |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1098 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1099 |
var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1100 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1101 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1102 |
* @see Walker::start_el() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1103 |
* @since 2.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1104 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1105 |
* @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
|
1106 |
* @param object $page Page data object. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1107 |
* @param int $depth Depth of page in reference to parent pages. Used for padding. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1108 |
* @param array $args Uses 'selected' argument for selected page to set selected HTML attribute for option element. |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1109 |
* @param int $id |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1110 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1111 |
function start_el(&$output, $page, $depth, $args, $id = 0) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1112 |
$pad = str_repeat(' ', $depth * 3); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1113 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1114 |
$output .= "\t<option class=\"level-$depth\" value=\"$page->ID\""; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1115 |
if ( $page->ID == $args['selected'] ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1116 |
$output .= ' selected="selected"'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1117 |
$output .= '>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1118 |
$title = apply_filters( 'list_pages', $page->post_title, $page ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1119 |
$output .= $pad . esc_html( $title ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1120 |
$output .= "</option>\n"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1121 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1122 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1123 |
|
136 | 1124 |
// |
1125 |
// Attachments |
|
1126 |
// |
|
1127 |
||
1128 |
/** |
|
1129 |
* Display an attachment page link using an image or icon. |
|
1130 |
* |
|
1131 |
* @since 2.0.0 |
|
1132 |
* |
|
1133 |
* @param int $id Optional. Post ID. |
|
1134 |
* @param bool $fullsize Optional, default is false. Whether to use full size. |
|
1135 |
* @param bool $deprecated Deprecated. Not used. |
|
1136 |
* @param bool $permalink Optional, default is false. Whether to include permalink. |
|
1137 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1138 |
function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $permalink = false ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1139 |
if ( !empty( $deprecated ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1140 |
_deprecated_argument( __FUNCTION__, '2.5' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1141 |
|
136 | 1142 |
if ( $fullsize ) |
1143 |
echo wp_get_attachment_link($id, 'full', $permalink); |
|
1144 |
else |
|
1145 |
echo wp_get_attachment_link($id, 'thumbnail', $permalink); |
|
1146 |
} |
|
1147 |
||
1148 |
/** |
|
1149 |
* Retrieve an attachment page link using an image or icon, if possible. |
|
1150 |
* |
|
1151 |
* @since 2.5.0 |
|
1152 |
* @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function. |
|
1153 |
* |
|
1154 |
* @param int $id Optional. Post ID. |
|
1155 |
* @param string $size Optional, default is 'thumbnail'. Size of image, either array or string. |
|
1156 |
* @param bool $permalink Optional, default is false. Whether to add permalink to image. |
|
1157 |
* @param bool $icon Optional, default is false. Whether to include icon. |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1158 |
* @param string|bool $text Optional, default is false. If string, then will be link text. |
136 | 1159 |
* @return string HTML content. |
1160 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1161 |
function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1162 |
$id = intval( $id ); |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1163 |
$_post = get_post( $id ); |
136 | 1164 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1165 |
if ( empty( $_post ) || ( 'attachment' != $_post->post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1166 |
return __( 'Missing Attachment' ); |
136 | 1167 |
|
1168 |
if ( $permalink ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1169 |
$url = get_attachment_link( $_post->ID ); |
136 | 1170 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1171 |
$post_title = esc_attr( $_post->post_title ); |
136 | 1172 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1173 |
if ( $text ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1174 |
$link_text = $text; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1175 |
elseif ( $size && 'none' != $size ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1176 |
$link_text = wp_get_attachment_image( $id, $size, $icon ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1177 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1178 |
$link_text = ''; |
136 | 1179 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1180 |
if ( trim( $link_text ) == '' ) |
136 | 1181 |
$link_text = $_post->post_title; |
1182 |
||
1183 |
return apply_filters( 'wp_get_attachment_link', "<a href='$url' title='$post_title'>$link_text</a>", $id, $size, $permalink, $icon, $text ); |
|
1184 |
} |
|
1185 |
||
1186 |
/** |
|
1187 |
* Wrap attachment in <<p>> element before content. |
|
1188 |
* |
|
1189 |
* @since 2.0.0 |
|
1190 |
* @uses apply_filters() Calls 'prepend_attachment' hook on HTML content. |
|
1191 |
* |
|
1192 |
* @param string $content |
|
1193 |
* @return string |
|
1194 |
*/ |
|
1195 |
function prepend_attachment($content) { |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1196 |
$post = get_post(); |
136 | 1197 |
|
1198 |
if ( empty($post->post_type) || $post->post_type != 'attachment' ) |
|
1199 |
return $content; |
|
1200 |
||
1201 |
$p = '<p class="attachment">'; |
|
1202 |
// show the medium sized image representation of the attachment if available, and link to the raw file |
|
1203 |
$p .= wp_get_attachment_link(0, 'medium', false); |
|
1204 |
$p .= '</p>'; |
|
1205 |
$p = apply_filters('prepend_attachment', $p); |
|
1206 |
||
1207 |
return "$p\n$content"; |
|
1208 |
} |
|
1209 |
||
1210 |
// |
|
1211 |
// Misc |
|
1212 |
// |
|
1213 |
||
1214 |
/** |
|
1215 |
* Retrieve protected post password form content. |
|
1216 |
* |
|
1217 |
* @since 1.0.0 |
|
1218 |
* @uses apply_filters() Calls 'the_password_form' filter on output. |
|
1219 |
* |
|
1220 |
* @return string HTML content for password form for password protected post. |
|
1221 |
*/ |
|
1222 |
function get_the_password_form() { |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1223 |
$post = get_post(); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1224 |
$label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1225 |
$output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" method="post"> |
136 | 1226 |
<p>' . __("This post is password protected. To view it please enter your password below:") . '</p> |
1227 |
<p><label for="' . $label . '">' . __("Password:") . ' <input name="post_password" id="' . $label . '" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . esc_attr__("Submit") . '" /></p> |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1228 |
</form> |
136 | 1229 |
'; |
1230 |
return apply_filters('the_password_form', $output); |
|
1231 |
} |
|
1232 |
||
1233 |
/** |
|
1234 |
* Whether currently in a page template. |
|
1235 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1236 |
* This template tag allows you to determine if you are in a page template. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1237 |
* You can optionally provide a template name and then the check will be |
136 | 1238 |
* specific to that template. |
1239 |
* |
|
1240 |
* @since 2.5.0 |
|
1241 |
* @uses $wp_query |
|
1242 |
* |
|
1243 |
* @param string $template The specific template name if specific matching is required. |
|
1244 |
* @return bool False on failure, true if success. |
|
1245 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1246 |
function is_page_template( $template = '' ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1247 |
if ( ! is_page() ) |
136 | 1248 |
return false; |
1249 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1250 |
$page_template = get_page_template_slug( get_queried_object_id() ); |
136 | 1251 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1252 |
if ( empty( $template ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1253 |
return (bool) $page_template; |
136 | 1254 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1255 |
if ( $template == $page_template ) |
136 | 1256 |
return true; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1257 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1258 |
if ( 'default' == $template && ! $page_template ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1259 |
return true; |
136 | 1260 |
|
1261 |
return false; |
|
1262 |
} |
|
1263 |
||
1264 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1265 |
* Get the specific template name for a page. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1266 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1267 |
* @since 3.4.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1268 |
* |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1269 |
* @param int $post_id The page ID to check. Defaults to the current post, when used in the loop. |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1270 |
* @return string|bool Page template filename. Returns an empty string when the default page template |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1271 |
* is in use. Returns false if the post is not a page. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1272 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1273 |
function get_page_template_slug( $post_id = null ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1274 |
$post = get_post( $post_id ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1275 |
if ( 'page' != $post->post_type ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1276 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1277 |
$template = get_post_meta( $post->ID, '_wp_page_template', true ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1278 |
if ( ! $template || 'default' == $template ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1279 |
return ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1280 |
return $template; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1281 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1282 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1283 |
/** |
136 | 1284 |
* Retrieve formatted date timestamp of a revision (linked to that revisions's page). |
1285 |
* |
|
1286 |
* @package WordPress |
|
1287 |
* @subpackage Post_Revisions |
|
1288 |
* @since 2.6.0 |
|
1289 |
* |
|
1290 |
* @uses date_i18n() |
|
1291 |
* |
|
1292 |
* @param int|object $revision Revision ID or revision object. |
|
1293 |
* @param bool $link Optional, default is true. Link to revisions's page? |
|
1294 |
* @return string i18n formatted datetimestamp or localized 'Current Revision'. |
|
1295 |
*/ |
|
1296 |
function wp_post_revision_title( $revision, $link = true ) { |
|
1297 |
if ( !$revision = get_post( $revision ) ) |
|
1298 |
return $revision; |
|
1299 |
||
1300 |
if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) ) |
|
1301 |
return false; |
|
1302 |
||
1303 |
/* translators: revision date format, see http://php.net/date */ |
|
1304 |
$datef = _x( 'j F, Y @ G:i', 'revision date format'); |
|
1305 |
/* translators: 1: date */ |
|
1306 |
$autosavef = __( '%1$s [Autosave]' ); |
|
1307 |
/* translators: 1: date */ |
|
1308 |
$currentf = __( '%1$s [Current Revision]' ); |
|
1309 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1310 |
$date = date_i18n( $datef, strtotime( $revision->post_modified ) ); |
136 | 1311 |
if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) ) |
1312 |
$date = "<a href='$link'>$date</a>"; |
|
1313 |
||
1314 |
if ( !wp_is_post_revision( $revision ) ) |
|
1315 |
$date = sprintf( $currentf, $date ); |
|
1316 |
elseif ( wp_is_post_autosave( $revision ) ) |
|
1317 |
$date = sprintf( $autosavef, $date ); |
|
1318 |
||
1319 |
return $date; |
|
1320 |
} |
|
1321 |
||
1322 |
/** |
|
1323 |
* Display list of a post's revisions. |
|
1324 |
* |
|
1325 |
* Can output either a UL with edit links or a TABLE with diff interface, and |
|
1326 |
* restore action links. |
|
1327 |
* |
|
1328 |
* Second argument controls parameters: |
|
1329 |
* (bool) parent : include the parent (the "Current Revision") in the list. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1330 |
* (string) format : 'list' or 'form-table'. 'list' outputs UL, 'form-table' |
136 | 1331 |
* outputs TABLE with UI. |
1332 |
* (int) right : what revision is currently being viewed - used in |
|
1333 |
* form-table format. |
|
1334 |
* (int) left : what revision is currently being diffed against right - |
|
1335 |
* used in form-table format. |
|
1336 |
* |
|
1337 |
* @package WordPress |
|
1338 |
* @subpackage Post_Revisions |
|
1339 |
* @since 2.6.0 |
|
1340 |
* |
|
1341 |
* @uses wp_get_post_revisions() |
|
1342 |
* @uses wp_post_revision_title() |
|
1343 |
* @uses get_edit_post_link() |
|
1344 |
* @uses get_the_author_meta() |
|
1345 |
* |
|
1346 |
* @todo split into two functions (list, form-table) ? |
|
1347 |
* |
|
1348 |
* @param int|object $post_id Post ID or post object. |
|
1349 |
* @param string|array $args See description {@link wp_parse_args()}. |
|
1350 |
* @return null |
|
1351 |
*/ |
|
1352 |
function wp_list_post_revisions( $post_id = 0, $args = null ) { |
|
1353 |
if ( !$post = get_post( $post_id ) ) |
|
1354 |
return; |
|
1355 |
||
1356 |
$defaults = array( 'parent' => false, 'right' => false, 'left' => false, 'format' => 'list', 'type' => 'all' ); |
|
1357 |
extract( wp_parse_args( $args, $defaults ), EXTR_SKIP ); |
|
1358 |
||
1359 |
switch ( $type ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1360 |
case 'autosave' : |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1361 |
if ( !$autosave = wp_get_post_autosave( $post->ID ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1362 |
return; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1363 |
$revisions = array( $autosave ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1364 |
break; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1365 |
case 'revision' : // just revisions - remove autosave later |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1366 |
case 'all' : |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1367 |
default : |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1368 |
if ( !$revisions = wp_get_post_revisions( $post->ID ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1369 |
return; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1370 |
break; |
136 | 1371 |
} |
1372 |
||
1373 |
/* translators: post revision: 1: when, 2: author name */ |
|
1374 |
$titlef = _x( '%1$s by %2$s', 'post revision' ); |
|
1375 |
||
1376 |
if ( $parent ) |
|
1377 |
array_unshift( $revisions, $post ); |
|
1378 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1379 |
$rows = $right_checked = ''; |
136 | 1380 |
$class = false; |
1381 |
$can_edit_post = current_user_can( 'edit_post', $post->ID ); |
|
1382 |
foreach ( $revisions as $revision ) { |
|
1383 |
if ( !current_user_can( 'read_post', $revision->ID ) ) |
|
1384 |
continue; |
|
1385 |
if ( 'revision' === $type && wp_is_post_autosave( $revision ) ) |
|
1386 |
continue; |
|
1387 |
||
1388 |
$date = wp_post_revision_title( $revision ); |
|
1389 |
$name = get_the_author_meta( 'display_name', $revision->post_author ); |
|
1390 |
||
1391 |
if ( 'form-table' == $format ) { |
|
1392 |
if ( $left ) |
|
1393 |
$left_checked = $left == $revision->ID ? ' checked="checked"' : ''; |
|
1394 |
else |
|
1395 |
$left_checked = $right_checked ? ' checked="checked"' : ''; // [sic] (the next one) |
|
1396 |
$right_checked = $right == $revision->ID ? ' checked="checked"' : ''; |
|
1397 |
||
1398 |
$class = $class ? '' : " class='alternate'"; |
|
1399 |
||
1400 |
if ( $post->ID != $revision->ID && $can_edit_post ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1401 |
$actions = '<a href="' . wp_nonce_url( add_query_arg( array( 'revision' => $revision->ID, 'action' => 'restore' ) ), "restore-post_$post->ID|$revision->ID" ) . '">' . __( 'Restore' ) . '</a>'; |
136 | 1402 |
else |
1403 |
$actions = ''; |
|
1404 |
||
1405 |
$rows .= "<tr$class>\n"; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1406 |
$rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='left' value='$revision->ID'$left_checked /></th>\n"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1407 |
$rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='right' value='$revision->ID'$right_checked /></th>\n"; |
136 | 1408 |
$rows .= "\t<td>$date</td>\n"; |
1409 |
$rows .= "\t<td>$name</td>\n"; |
|
1410 |
$rows .= "\t<td class='action-links'>$actions</td>\n"; |
|
1411 |
$rows .= "</tr>\n"; |
|
1412 |
} else { |
|
1413 |
$title = sprintf( $titlef, $date, $name ); |
|
1414 |
$rows .= "\t<li>$title</li>\n"; |
|
1415 |
} |
|
1416 |
} |
|
1417 |
||
1418 |
if ( 'form-table' == $format ) : ?> |
|
1419 |
||
1420 |
<form action="revision.php" method="get"> |
|
1421 |
||
1422 |
<div class="tablenav"> |
|
1423 |
<div class="alignleft"> |
|
1424 |
<input type="submit" class="button-secondary" value="<?php esc_attr_e( 'Compare Revisions' ); ?>" /> |
|
1425 |
<input type="hidden" name="action" value="diff" /> |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1426 |
<input type="hidden" name="post_type" value="<?php echo esc_attr($post->post_type); ?>" /> |
136 | 1427 |
</div> |
1428 |
</div> |
|
1429 |
||
1430 |
<br class="clear" /> |
|
1431 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1432 |
<table class="widefat post-revisions" cellspacing="0" id="post-revisions"> |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1433 |
<col /> |
136 | 1434 |
<col /> |
1435 |
<col style="width: 33%" /> |
|
1436 |
<col style="width: 33%" /> |
|
1437 |
<col style="width: 33%" /> |
|
1438 |
<thead> |
|
1439 |
<tr> |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1440 |
<th scope="col"><?php /* translators: column name in revisions */ _ex( 'Old', 'revisions column name' ); ?></th> |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1441 |
<th scope="col"><?php /* translators: column name in revisions */ _ex( 'New', 'revisions column name' ); ?></th> |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1442 |
<th scope="col"><?php /* translators: column name in revisions */ _ex( 'Date Created', 'revisions column name' ); ?></th> |
136 | 1443 |
<th scope="col"><?php _e( 'Author' ); ?></th> |
1444 |
<th scope="col" class="action-links"><?php _e( 'Actions' ); ?></th> |
|
1445 |
</tr> |
|
1446 |
</thead> |
|
1447 |
<tbody> |
|
1448 |
||
1449 |
<?php echo $rows; ?> |
|
1450 |
||
1451 |
</tbody> |
|
1452 |
</table> |
|
1453 |
||
1454 |
</form> |
|
1455 |
||
1456 |
<?php |
|
1457 |
else : |
|
1458 |
echo "<ul class='post-revisions'>\n"; |
|
1459 |
echo $rows; |
|
1460 |
echo "</ul>"; |
|
1461 |
endif; |
|
1462 |
||
1463 |
} |