1915 * @param string $url URL to archive. |
1914 * @param string $url URL to archive. |
1916 * @param string $text Archive text description. |
1915 * @param string $text Archive text description. |
1917 * @param string $format Optional. Can be 'link', 'option', 'html', or custom. Default 'html'. |
1916 * @param string $format Optional. Can be 'link', 'option', 'html', or custom. Default 'html'. |
1918 * @param string $before Optional. Content to prepend to the description. Default empty. |
1917 * @param string $before Optional. Content to prepend to the description. Default empty. |
1919 * @param string $after Optional. Content to append to the description. Default empty. |
1918 * @param string $after Optional. Content to append to the description. Default empty. |
1920 * @param bool $selected Optional. Set to true if the current page is the selected archive page. |
1919 * @param bool $selected Optional. Set to true if the current page is the selected archive page. Default false. |
1921 * @return string HTML link content for archive. |
1920 * @return string HTML link content for archive. |
1922 */ |
1921 */ |
1923 function get_archives_link( $url, $text, $format = 'html', $before = '', $after = '', $selected = false ) { |
1922 function get_archives_link( $url, $text, $format = 'html', $before = '', $after = '', $selected = false ) { |
1924 $text = wptexturize( $text ); |
1923 $text = wptexturize( $text ); |
1925 $url = esc_url( $url ); |
1924 $url = esc_url( $url ); |
2232 * |
2231 * |
2233 * The calendar is cached, which will be retrieved, if it exists. If there are |
2232 * The calendar is cached, which will be retrieved, if it exists. If there are |
2234 * no posts for the month, then it will not be displayed. |
2233 * no posts for the month, then it will not be displayed. |
2235 * |
2234 * |
2236 * @since 1.0.0 |
2235 * @since 1.0.0 |
|
2236 * @since 6.8.0 Added the `$args` parameter, with backward compatibility |
|
2237 * for the replaced `$initial` and `$display` parameters. |
2237 * |
2238 * |
2238 * @global wpdb $wpdb WordPress database abstraction object. |
2239 * @global wpdb $wpdb WordPress database abstraction object. |
2239 * @global int $m |
2240 * @global int $m |
2240 * @global int $monthnum |
2241 * @global int $monthnum |
2241 * @global int $year |
2242 * @global int $year |
2242 * @global WP_Locale $wp_locale WordPress date and time locale object. |
2243 * @global WP_Locale $wp_locale WordPress date and time locale object. |
2243 * @global array $posts |
2244 * @global array $posts |
2244 * |
2245 * |
2245 * @param bool $initial Optional. Whether to use initial calendar names. Default true. |
2246 * @param array $args { |
2246 * @param bool $display Optional. Whether to display the calendar output. Default true. |
2247 * Optional. Arguments for the `get_calendar` function. |
|
2248 * |
|
2249 * @type bool $initial Whether to use initial calendar names. Default true. |
|
2250 * @type bool $display Whether to display the calendar output. Default true. |
|
2251 * @type string $post_type Optional. Post type. Default 'post'. |
|
2252 * } |
2247 * @return void|string Void if `$display` argument is true, calendar HTML if `$display` is false. |
2253 * @return void|string Void if `$display` argument is true, calendar HTML if `$display` is false. |
2248 */ |
2254 */ |
2249 function get_calendar( $initial = true, $display = true ) { |
2255 function get_calendar( $args = array() ) { |
2250 global $wpdb, $m, $monthnum, $year, $wp_locale, $posts; |
2256 global $wpdb, $m, $monthnum, $year, $wp_locale, $posts; |
2251 |
2257 |
2252 $key = md5( $m . $monthnum . $year ); |
2258 $defaults = array( |
|
2259 'initial' => true, |
|
2260 'display' => true, |
|
2261 'post_type' => 'post', |
|
2262 ); |
|
2263 |
|
2264 $original_args = func_get_args(); |
|
2265 $args = array(); |
|
2266 |
|
2267 if ( ! empty( $original_args ) ) { |
|
2268 if ( ! is_array( $original_args[0] ) ) { |
|
2269 if ( isset( $original_args[0] ) && is_bool( $original_args[0] ) ) { |
|
2270 $defaults['initial'] = $original_args[0]; |
|
2271 } |
|
2272 if ( isset( $original_args[1] ) && is_bool( $original_args[1] ) ) { |
|
2273 $defaults['display'] = $original_args[1]; |
|
2274 } |
|
2275 } else { |
|
2276 $args = $original_args[0]; |
|
2277 } |
|
2278 } |
|
2279 |
|
2280 /** |
|
2281 * Filter the `get_calendar` function arguments before they are used. |
|
2282 * |
|
2283 * @since 6.8.0 |
|
2284 * |
|
2285 * @param array $args { |
|
2286 * Optional. Arguments for the `get_calendar` function. |
|
2287 * |
|
2288 * @type bool $initial Whether to use initial calendar names. Default true. |
|
2289 * @type bool $display Whether to display the calendar output. Default true. |
|
2290 * @type string $post_type Optional. Post type. Default 'post'. |
|
2291 * } |
|
2292 * @return array The arguments for the `get_calendar` function. |
|
2293 */ |
|
2294 $args = apply_filters( 'get_calendar_args', wp_parse_args( $args, $defaults ) ); |
|
2295 |
|
2296 if ( ! post_type_exists( $args['post_type'] ) ) { |
|
2297 $args['post_type'] = 'post'; |
|
2298 } |
|
2299 |
|
2300 $w = 0; |
|
2301 if ( isset( $_GET['w'] ) ) { |
|
2302 $w = (int) $_GET['w']; |
|
2303 } |
|
2304 |
|
2305 /* |
|
2306 * Normalize the cache key. |
|
2307 * |
|
2308 * The following ensures the same cache key is used for the same parameter |
|
2309 * and parameter equivalents. This prevents `post_type > post, initial > true` |
|
2310 * from generating a different key from the same values in the reverse order. |
|
2311 * |
|
2312 * `display` is excluded from the cache key as the cache contains the same |
|
2313 * HTML regardless of this function's need to echo or return the output. |
|
2314 * |
|
2315 * The global values contain data generated by the URL query string variables. |
|
2316 */ |
|
2317 $cache_args = $args; |
|
2318 unset( $cache_args['display'] ); |
|
2319 |
|
2320 $cache_args['globals'] = array( |
|
2321 'm' => $m, |
|
2322 'monthnum' => $monthnum, |
|
2323 'year' => $year, |
|
2324 'week' => $w, |
|
2325 ); |
|
2326 |
|
2327 wp_recursive_ksort( $cache_args ); |
|
2328 $key = md5( serialize( $cache_args ) ); |
2253 $cache = wp_cache_get( 'get_calendar', 'calendar' ); |
2329 $cache = wp_cache_get( 'get_calendar', 'calendar' ); |
2254 |
2330 |
2255 if ( $cache && is_array( $cache ) && isset( $cache[ $key ] ) ) { |
2331 if ( $cache && is_array( $cache ) && isset( $cache[ $key ] ) ) { |
2256 /** This filter is documented in wp-includes/general-template.php */ |
2332 /** This filter is documented in wp-includes/general-template.php */ |
2257 $output = apply_filters( 'get_calendar', $cache[ $key ] ); |
2333 $output = apply_filters( 'get_calendar', $cache[ $key ], $args ); |
2258 |
2334 |
2259 if ( $display ) { |
2335 if ( $args['display'] ) { |
2260 echo $output; |
2336 echo $output; |
2261 return; |
2337 return; |
2262 } |
2338 } |
2263 |
2339 |
2264 return $output; |
2340 return $output; |
2266 |
2342 |
2267 if ( ! is_array( $cache ) ) { |
2343 if ( ! is_array( $cache ) ) { |
2268 $cache = array(); |
2344 $cache = array(); |
2269 } |
2345 } |
2270 |
2346 |
|
2347 $post_type = $args['post_type']; |
|
2348 |
2271 // Quick check. If we have no posts at all, abort! |
2349 // Quick check. If we have no posts at all, abort! |
2272 if ( ! $posts ) { |
2350 if ( ! $posts ) { |
2273 $gotsome = $wpdb->get_var( "SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1" ); |
2351 $gotsome = $wpdb->get_var( |
|
2352 $wpdb->prepare( |
|
2353 "SELECT 1 as test |
|
2354 FROM $wpdb->posts |
|
2355 WHERE post_type = %s |
|
2356 AND post_status = 'publish' |
|
2357 LIMIT 1", |
|
2358 $post_type |
|
2359 ) |
|
2360 ); |
|
2361 |
2274 if ( ! $gotsome ) { |
2362 if ( ! $gotsome ) { |
2275 $cache[ $key ] = ''; |
2363 $cache[ $key ] = ''; |
2276 wp_cache_set( 'get_calendar', $cache, 'calendar' ); |
2364 wp_cache_set( 'get_calendar', $cache, 'calendar' ); |
2277 return; |
2365 return; |
2278 } |
2366 } |
2279 } |
2367 } |
2280 |
2368 |
2281 if ( isset( $_GET['w'] ) ) { |
|
2282 $w = (int) $_GET['w']; |
|
2283 } |
|
2284 // week_begins = 0 stands for Sunday. |
2369 // week_begins = 0 stands for Sunday. |
2285 $week_begins = (int) get_option( 'start_of_week' ); |
2370 $week_begins = (int) get_option( 'start_of_week' ); |
2286 |
2371 |
2287 // Let's figure out when we are. |
2372 // Let's figure out when we are. |
2288 if ( ! empty( $monthnum ) && ! empty( $year ) ) { |
2373 if ( ! empty( $monthnum ) && ! empty( $year ) ) { |
2289 $thismonth = zeroise( (int) $monthnum, 2 ); |
2374 $thismonth = (int) $monthnum; |
2290 $thisyear = (int) $year; |
2375 $thisyear = (int) $year; |
2291 } elseif ( ! empty( $w ) ) { |
2376 } elseif ( ! empty( $w ) ) { |
2292 // We need to get the month from MySQL. |
2377 // We need to get the month from MySQL. |
2293 $thisyear = (int) substr( $m, 0, 4 ); |
2378 $thisyear = (int) substr( $m, 0, 4 ); |
2294 // It seems MySQL's weeks disagree with PHP's. |
2379 // It seems MySQL's weeks disagree with PHP's. |
2295 $d = ( ( $w - 1 ) * 7 ) + 6; |
2380 $d = ( ( $w - 1 ) * 7 ) + 6; |
2296 $thismonth = $wpdb->get_var( "SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')" ); |
2381 $thismonth = (int) $wpdb->get_var( |
|
2382 $wpdb->prepare( |
|
2383 "SELECT DATE_FORMAT((DATE_ADD('%d0101', INTERVAL %d DAY) ), '%%m')", |
|
2384 $thisyear, |
|
2385 $d |
|
2386 ) |
|
2387 ); |
2297 } elseif ( ! empty( $m ) ) { |
2388 } elseif ( ! empty( $m ) ) { |
2298 $thisyear = (int) substr( $m, 0, 4 ); |
2389 $thisyear = (int) substr( $m, 0, 4 ); |
2299 if ( strlen( $m ) < 6 ) { |
2390 if ( strlen( $m ) < 6 ) { |
2300 $thismonth = '01'; |
2391 $thismonth = 1; |
2301 } else { |
2392 } else { |
2302 $thismonth = zeroise( (int) substr( $m, 4, 2 ), 2 ); |
2393 $thismonth = (int) substr( $m, 4, 2 ); |
2303 } |
2394 } |
2304 } else { |
2395 } else { |
2305 $thisyear = current_time( 'Y' ); |
2396 $thisyear = (int) current_time( 'Y' ); |
2306 $thismonth = current_time( 'm' ); |
2397 $thismonth = (int) current_time( 'm' ); |
2307 } |
2398 } |
2308 |
2399 |
2309 $unixmonth = mktime( 0, 0, 0, $thismonth, 1, $thisyear ); |
2400 $unixmonth = mktime( 0, 0, 0, $thismonth, 1, $thisyear ); |
2310 $last_day = gmdate( 't', $unixmonth ); |
2401 $last_day = gmdate( 't', $unixmonth ); |
2311 |
2402 |
2312 // Get the next and previous month and year with at least one post. |
2403 // Get the next and previous month and year with at least one post. |
2313 $previous = $wpdb->get_row( |
2404 $previous = $wpdb->get_row( |
2314 "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year |
2405 $wpdb->prepare( |
2315 FROM $wpdb->posts |
2406 "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year |
2316 WHERE post_date < '$thisyear-$thismonth-01' |
2407 FROM $wpdb->posts |
2317 AND post_type = 'post' AND post_status = 'publish' |
2408 WHERE post_date < '%d-%d-01' |
2318 ORDER BY post_date DESC |
2409 AND post_type = %s AND post_status = 'publish' |
2319 LIMIT 1" |
2410 ORDER BY post_date DESC |
|
2411 LIMIT 1", |
|
2412 $thisyear, |
|
2413 zeroise( $thismonth, 2 ), |
|
2414 $post_type |
|
2415 ) |
2320 ); |
2416 ); |
2321 $next = $wpdb->get_row( |
2417 |
2322 "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year |
2418 $next = $wpdb->get_row( |
2323 FROM $wpdb->posts |
2419 $wpdb->prepare( |
2324 WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59' |
2420 "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year |
2325 AND post_type = 'post' AND post_status = 'publish' |
2421 FROM $wpdb->posts |
2326 ORDER BY post_date ASC |
2422 WHERE post_date > '%d-%d-%d 23:59:59' |
2327 LIMIT 1" |
2423 AND post_type = %s AND post_status = 'publish' |
|
2424 ORDER BY post_date ASC |
|
2425 LIMIT 1", |
|
2426 $thisyear, |
|
2427 zeroise( $thismonth, 2 ), |
|
2428 $last_day, |
|
2429 $post_type |
|
2430 ) |
2328 ); |
2431 ); |
2329 |
2432 |
2330 /* translators: Calendar caption: 1: Month name, 2: 4-digit year. */ |
2433 /* translators: Calendar caption: 1: Month name, 2: 4-digit year. */ |
2331 $calendar_caption = _x( '%1$s %2$s', 'calendar caption' ); |
2434 $calendar_caption = _x( '%1$s %2$s', 'calendar caption' ); |
2332 $calendar_output = '<table id="wp-calendar" class="wp-calendar-table"> |
2435 $calendar_output = '<table id="wp-calendar" class="wp-calendar-table"> |
2358 |
2461 |
2359 $daywithpost = array(); |
2462 $daywithpost = array(); |
2360 |
2463 |
2361 // Get days with posts. |
2464 // Get days with posts. |
2362 $dayswithposts = $wpdb->get_results( |
2465 $dayswithposts = $wpdb->get_results( |
2363 "SELECT DISTINCT DAYOFMONTH(post_date) |
2466 $wpdb->prepare( |
2364 FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' |
2467 "SELECT DISTINCT DAYOFMONTH(post_date) |
2365 AND post_type = 'post' AND post_status = 'publish' |
2468 FROM $wpdb->posts WHERE post_date >= '%d-%d-01 00:00:00' |
2366 AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", |
2469 AND post_type = %s AND post_status = 'publish' |
|
2470 AND post_date <= '%d-%d-%d 23:59:59'", |
|
2471 $thisyear, |
|
2472 zeroise( $thismonth, 2 ), |
|
2473 $post_type, |
|
2474 $thisyear, |
|
2475 zeroise( $thismonth, 2 ), |
|
2476 $last_day |
|
2477 ), |
2367 ARRAY_N |
2478 ARRAY_N |
2368 ); |
2479 ); |
2369 |
2480 |
2370 if ( $dayswithposts ) { |
2481 if ( $dayswithposts ) { |
2371 foreach ( (array) $dayswithposts as $daywith ) { |
2482 foreach ( (array) $dayswithposts as $daywith ) { |
2372 $daywithpost[] = (int) $daywith[0]; |
2483 $daywithpost[] = (int) $daywith[0]; |
2373 } |
2484 } |
2374 } |
2485 } |
2375 |
2486 |
2376 // See how much we should pad in the beginning. |
2487 // See how much we should pad in the beginning. |
2377 $pad = calendar_week_mod( gmdate( 'w', $unixmonth ) - $week_begins ); |
2488 $pad = calendar_week_mod( (int) gmdate( 'w', $unixmonth ) - $week_begins ); |
2378 if ( 0 != $pad ) { |
2489 if ( $pad > 0 ) { |
2379 $calendar_output .= "\n\t\t" . '<td colspan="' . esc_attr( $pad ) . '" class="pad"> </td>'; |
2490 $calendar_output .= "\n\t\t" . '<td colspan="' . esc_attr( $pad ) . '" class="pad"> </td>'; |
2380 } |
2491 } |
2381 |
2492 |
2382 $newrow = false; |
2493 $newrow = false; |
2383 $daysinmonth = (int) gmdate( 't', $unixmonth ); |
2494 $daysinmonth = (int) gmdate( 't', $unixmonth ); |
2384 |
2495 |
2385 for ( $day = 1; $day <= $daysinmonth; ++$day ) { |
2496 for ( $day = 1; $day <= $daysinmonth; ++$day ) { |
2386 if ( isset( $newrow ) && $newrow ) { |
2497 if ( isset( $newrow ) && $newrow ) { |
2387 $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t"; |
2498 $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t"; |
2388 } |
2499 } |
|
2500 |
2389 $newrow = false; |
2501 $newrow = false; |
2390 |
2502 |
2391 if ( current_time( 'j' ) == $day && |
2503 if ( (int) current_time( 'j' ) === $day |
2392 current_time( 'm' ) == $thismonth && |
2504 && (int) current_time( 'm' ) === $thismonth |
2393 current_time( 'Y' ) == $thisyear ) { |
2505 && (int) current_time( 'Y' ) === $thisyear |
|
2506 ) { |
2394 $calendar_output .= '<td id="today">'; |
2507 $calendar_output .= '<td id="today">'; |
2395 } else { |
2508 } else { |
2396 $calendar_output .= '<td>'; |
2509 $calendar_output .= '<td>'; |
2397 } |
2510 } |
2398 |
2511 |
2411 $calendar_output .= $day; |
2524 $calendar_output .= $day; |
2412 } |
2525 } |
2413 |
2526 |
2414 $calendar_output .= '</td>'; |
2527 $calendar_output .= '</td>'; |
2415 |
2528 |
2416 if ( 6 == calendar_week_mod( gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ) ) { |
2529 if ( 6 === (int) calendar_week_mod( (int) gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ) ) { |
2417 $newrow = true; |
2530 $newrow = true; |
2418 } |
2531 } |
2419 } |
2532 } |
2420 |
2533 |
2421 $pad = 7 - calendar_week_mod( gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ); |
2534 $pad = 7 - calendar_week_mod( (int) gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ); |
2422 if ( 0 != $pad && 7 != $pad ) { |
2535 if ( 0 < $pad && $pad < 7 ) { |
2423 $calendar_output .= "\n\t\t" . '<td class="pad" colspan="' . esc_attr( $pad ) . '"> </td>'; |
2536 $calendar_output .= "\n\t\t" . '<td class="pad" colspan="' . esc_attr( $pad ) . '"> </td>'; |
2424 } |
2537 } |
2425 |
2538 |
2426 $calendar_output .= "\n\t</tr>\n\t</tbody>"; |
2539 $calendar_output .= "\n\t</tr>\n\t</tbody>"; |
2427 |
2540 |
2428 $calendar_output .= "\n\t</table>"; |
2541 $calendar_output .= "\n\t</table>"; |
2429 |
2542 |
2430 $calendar_output .= '<nav aria-label="' . __( 'Previous and next months' ) . '" class="wp-calendar-nav">'; |
2543 $calendar_output .= '<nav aria-label="' . __( 'Previous and next months' ) . '" class="wp-calendar-nav">'; |
2431 |
2544 |
2432 if ( $previous ) { |
2545 if ( $previous ) { |
2433 $calendar_output .= "\n\t\t" . '<span class="wp-calendar-nav-prev"><a href="' . get_month_link( $previous->year, $previous->month ) . '">« ' . |
2546 $calendar_output .= "\n\t\t" . sprintf( |
2434 $wp_locale->get_month_abbrev( $wp_locale->get_month( $previous->month ) ) . |
2547 '<span class="wp-calendar-nav-prev"><a href="%1$s">« %2$s</a></span>', |
2435 '</a></span>'; |
2548 get_month_link( $previous->year, $previous->month ), |
|
2549 $wp_locale->get_month_abbrev( $wp_locale->get_month( $previous->month ) ) |
|
2550 ); |
2436 } else { |
2551 } else { |
2437 $calendar_output .= "\n\t\t" . '<span class="wp-calendar-nav-prev"> </span>'; |
2552 $calendar_output .= "\n\t\t" . '<span class="wp-calendar-nav-prev"> </span>'; |
2438 } |
2553 } |
2439 |
2554 |
2440 $calendar_output .= "\n\t\t" . '<span class="pad"> </span>'; |
2555 $calendar_output .= "\n\t\t" . '<span class="pad"> </span>'; |
2441 |
2556 |
2442 if ( $next ) { |
2557 if ( $next ) { |
2443 $calendar_output .= "\n\t\t" . '<span class="wp-calendar-nav-next"><a href="' . get_month_link( $next->year, $next->month ) . '">' . |
2558 $calendar_output .= "\n\t\t" . sprintf( |
2444 $wp_locale->get_month_abbrev( $wp_locale->get_month( $next->month ) ) . |
2559 '<span class="wp-calendar-nav-next"><a href="%1$s">%2$s »</a></span>', |
2445 ' »</a></span>'; |
2560 get_month_link( $next->year, $next->month ), |
|
2561 $wp_locale->get_month_abbrev( $wp_locale->get_month( $next->month ) ) |
|
2562 ); |
2446 } else { |
2563 } else { |
2447 $calendar_output .= "\n\t\t" . '<span class="wp-calendar-nav-next"> </span>'; |
2564 $calendar_output .= "\n\t\t" . '<span class="wp-calendar-nav-next"> </span>'; |
2448 } |
2565 } |
2449 |
2566 |
2450 $calendar_output .= ' |
2567 $calendar_output .= ' |
2451 </nav>'; |
2568 </nav>'; |
2452 |
2569 |
2453 $cache[ $key ] = $calendar_output; |
2570 $cache[ $key ] = $calendar_output; |
2454 wp_cache_set( 'get_calendar', $cache, 'calendar' ); |
2571 wp_cache_set( 'get_calendar', $cache, 'calendar' ); |
2455 |
2572 |
2456 if ( $display ) { |
2573 /** |
2457 /** |
2574 * Filters the HTML calendar output. |
2458 * Filters the HTML calendar output. |
2575 * |
2459 * |
2576 * @since 3.0.0 |
2460 * @since 3.0.0 |
2577 * @since 6.8.0 Added the `$args` parameter. |
2461 * |
2578 * |
2462 * @param string $calendar_output HTML output of the calendar. |
2579 * @param string $calendar_output HTML output of the calendar. |
2463 */ |
2580 * @param array $args { |
2464 echo apply_filters( 'get_calendar', $calendar_output ); |
2581 * Optional. Array of display arguments. |
|
2582 * |
|
2583 * @type bool $initial Whether to use initial calendar names. Default true. |
|
2584 * @type bool $display Whether to display the calendar output. Default true. |
|
2585 * @type string $post_type Optional. Post type. Default 'post'. |
|
2586 * } |
|
2587 */ |
|
2588 $calendar_output = apply_filters( 'get_calendar', $calendar_output, $args ); |
|
2589 |
|
2590 if ( $args['display'] ) { |
|
2591 echo $calendar_output; |
2465 return; |
2592 return; |
2466 } |
2593 } |
2467 /** This filter is documented in wp-includes/general-template.php */ |
2594 |
2468 return apply_filters( 'get_calendar', $calendar_output ); |
2595 return $calendar_output; |
2469 } |
2596 } |
2470 |
2597 |
2471 /** |
2598 /** |
2472 * Purges the cached results of get_calendar. |
2599 * Purges the cached results of get_calendar. |
2473 * |
2600 * |
2516 function the_date_xml() { |
2643 function the_date_xml() { |
2517 echo mysql2date( 'Y-m-d', get_post()->post_date, false ); |
2644 echo mysql2date( 'Y-m-d', get_post()->post_date, false ); |
2518 } |
2645 } |
2519 |
2646 |
2520 /** |
2647 /** |
2521 * Displays or retrieves the date the current post was written (once per date) |
2648 * Displays or retrieves the date of the post (once per date). |
2522 * |
2649 * |
2523 * Will only output the date if the current post's date is different from the |
2650 * Will only output the date if the current post's date is different from the |
2524 * previous one output. |
2651 * previous one output. |
2525 * |
2652 * |
2526 * i.e. Only one date listing will show per day worth of posts shown in the loop, even if the |
2653 * i.e. Only one date listing will show per day worth of posts shown in the loop, even if the |
2527 * function is called several times for each post. |
2654 * function is called several times for each post. |
2528 * |
2655 * |
2529 * HTML output can be filtered with 'the_date'. |
2656 * HTML output can be filtered with {@see 'the_date'}. |
2530 * Date string output can be filtered with 'get_the_date'. |
2657 * Date string output can be filtered with {@see 'get_the_date'}. |
2531 * |
2658 * |
2532 * @since 0.71 |
2659 * @since 0.71 |
2533 * |
2660 * |
2534 * @global string $currentday The day of the current post in the loop. |
2661 * @global string $currentday The day of the current post in the loop. |
2535 * @global string $previousday The day of the previous post in the loop. |
2662 * @global string $previousday The day of the previous post in the loop. |
2617 */ |
2744 */ |
2618 function the_modified_date( $format = '', $before = '', $after = '', $display = true ) { |
2745 function the_modified_date( $format = '', $before = '', $after = '', $display = true ) { |
2619 $the_modified_date = $before . get_the_modified_date( $format ) . $after; |
2746 $the_modified_date = $before . get_the_modified_date( $format ) . $after; |
2620 |
2747 |
2621 /** |
2748 /** |
2622 * Filters the date a post was last modified for display. |
2749 * Filters the date a post was last modified, for display. |
2623 * |
2750 * |
2624 * @since 2.1.0 |
2751 * @since 2.1.0 |
2625 * |
2752 * |
2626 * @param string|false $the_modified_date The last modified date or false if no post is found. |
2753 * @param string $the_modified_date The last modified date. |
2627 * @param string $format PHP date format. |
2754 * @param string $format PHP date format. |
2628 * @param string $before HTML output before the date. |
2755 * @param string $before HTML output before the date. |
2629 * @param string $after HTML output after the date. |
2756 * @param string $after HTML output after the date. |
2630 */ |
2757 */ |
2631 $the_modified_date = apply_filters( 'the_modified_date', $the_modified_date, $format, $before, $after ); |
2758 $the_modified_date = apply_filters( 'the_modified_date', $the_modified_date, $format, $before, $after ); |
2632 |
2759 |
2633 if ( $display ) { |
2760 if ( $display ) { |
2634 echo $the_modified_date; |
2761 echo $the_modified_date; |
2671 */ |
2798 */ |
2672 return apply_filters( 'get_the_modified_date', $the_time, $format, $post ); |
2799 return apply_filters( 'get_the_modified_date', $the_time, $format, $post ); |
2673 } |
2800 } |
2674 |
2801 |
2675 /** |
2802 /** |
2676 * Displays the time at which the post was written. |
2803 * Displays the time of the post. |
2677 * |
2804 * |
2678 * @since 0.71 |
2805 * @since 0.71 |
2679 * |
2806 * |
2680 * @param string $format Optional. Format to use for retrieving the time the post |
2807 * @param string $format Optional. Format to use for retrieving the time the post |
2681 * was written. Accepts 'G', 'U', or PHP date format. |
2808 * was written. Accepts 'G', 'U', or PHP date format. |
2682 * Defaults to the 'time_format' option. |
2809 * Defaults to the 'time_format' option. |
2683 */ |
2810 */ |
2684 function the_time( $format = '' ) { |
2811 function the_time( $format = '' ) { |
2685 /** |
2812 /** |
2686 * Filters the time a post was written for display. |
2813 * Filters the time of the post, for display. |
2687 * |
2814 * |
2688 * @since 0.71 |
2815 * @since 0.71 |
2689 * |
2816 * |
2690 * @param string $get_the_time The formatted time. |
2817 * @param string $get_the_time The formatted time. |
2691 * @param string $format Format to use for retrieving the time the post |
2818 * @param string $format Format to use for retrieving the time the post |
2716 $_format = ! empty( $format ) ? $format : get_option( 'time_format' ); |
2843 $_format = ! empty( $format ) ? $format : get_option( 'time_format' ); |
2717 |
2844 |
2718 $the_time = get_post_time( $_format, false, $post, true ); |
2845 $the_time = get_post_time( $_format, false, $post, true ); |
2719 |
2846 |
2720 /** |
2847 /** |
2721 * Filters the time a post was written. |
2848 * Filters the time of the post. |
2722 * |
2849 * |
2723 * @since 1.5.0 |
2850 * @since 1.5.0 |
2724 * |
2851 * |
2725 * @param string|int $the_time Formatted date string or Unix timestamp if `$format` is 'U' or 'G'. |
2852 * @param string|int $the_time Formatted date string or Unix timestamp if `$format` is 'U' or 'G'. |
2726 * @param string $format Format to use for retrieving the time the post |
2853 * @param string $format Format to use for retrieving the time the post |
2727 * was written. Accepts 'G', 'U', or PHP date format. |
2854 * was written. Accepts 'G', 'U', or PHP date format. |
2728 * @param WP_Post $post Post object. |
2855 * @param WP_Post $post Post object. |
2729 */ |
2856 */ |
2730 return apply_filters( 'get_the_time', $the_time, $format, $post ); |
2857 return apply_filters( 'get_the_time', $the_time, $format, $post ); |
2731 } |
2858 } |
2732 |
2859 |
2733 /** |
2860 /** |
2734 * Retrieves the time at which the post was written. |
2861 * Retrieves the localized time of the post. |
2735 * |
2862 * |
2736 * @since 2.0.0 |
2863 * @since 2.0.0 |
2737 * |
2864 * |
2738 * @param string $format Optional. Format to use for retrieving the time the post |
2865 * @param string $format Optional. Format to use for retrieving the time the post |
2739 * was written. Accepts 'G', 'U', or PHP date format. Default 'U'. |
2866 * was written. Accepts 'G', 'U', or PHP date format. Default 'U'. |
4582 $args['prev_text'] |
4727 $args['prev_text'] |
4583 ); |
4728 ); |
4584 endif; |
4729 endif; |
4585 |
4730 |
4586 for ( $n = 1; $n <= $total; $n++ ) : |
4731 for ( $n = 1; $n <= $total; $n++ ) : |
4587 if ( $n == $current ) : |
4732 if ( $n === $current ) : |
4588 $page_links[] = sprintf( |
4733 $page_links[] = sprintf( |
4589 '<span aria-current="%s" class="page-numbers current">%s</span>', |
4734 '<span aria-current="%s" class="page-numbers current">%s</span>', |
4590 esc_attr( $args['aria_current'] ), |
4735 esc_attr( $args['aria_current'] ), |
4591 $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] |
4736 $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] |
4592 ); |
4737 ); |
4593 |
4738 |
4594 $dots = true; |
4739 $dots = true; |
4595 else : |
4740 else : |
4596 if ( $args['show_all'] || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) : |
4741 if ( $args['show_all'] || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) : |
4597 $link = str_replace( '%_%', 1 == $n ? '' : $args['format'], $args['base'] ); |
4742 $link = str_replace( '%_%', 1 === $n ? '' : $args['format'], $args['base'] ); |
4598 $link = str_replace( '%#%', $n, $link ); |
4743 $link = str_replace( '%#%', $n, $link ); |
4599 if ( $add_args ) { |
4744 if ( $add_args ) { |
4600 $link = add_query_arg( $add_args, $link ); |
4745 $link = add_query_arg( $add_args, $link ); |
4601 } |
4746 } |
4602 $link .= $args['add_fragment']; |
4747 $link .= $args['add_fragment']; |