get_day_link( bool|int $year, bool|int $month, bool|int $day )
Retrieves the permalink for the day archives with year and month.
描述
参数
- $year
-
(bool|int)
(Required)
False for current year. Integer of year. - $month
-
(bool|int)
(Required)
False for current month. Integer of month. - $day
-
(bool|int)
(Required)
False for current day. Integer of day.
返回值
(string) The permalink for the specified day, month, and year archive.
源代码
File: wp-includes/link-template.php
function get_day_link($year, $month, $day) {
global $wp_rewrite;
if ( !$year )
$year = gmdate('Y', current_time('timestamp'));
if ( !$month )
$month = gmdate('m', current_time('timestamp'));
if ( !$day )
$day = gmdate('j', current_time('timestamp'));
$daylink = $wp_rewrite->get_day_permastruct();
if ( !empty($daylink) ) {
$daylink = str_replace('%year%', $year, $daylink);
$daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink);
$daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink);
$daylink = home_url( user_trailingslashit( $daylink, 'day' ) );
} else {
$daylink = home_url( '?m=' . $year . zeroise( $month, 2 ) . zeroise( $day, 2 ) );
}
/**
* Filters the day archive permalink.
*
* @since 1.5.0
*
* @param string $daylink Permalink for the day archive.
* @param int $year Year for the archive.
* @param int $month Month for the archive.
* @param int $day The day for the archive.
*/
return apply_filters( 'day_link', $daylink, $year, $month, $day );
}
更新日志
Version | 描述 |
---|---|
1.0.0 | Introduced. |
相关函数
Uses
-
wp-includes/formatting.php:
zeroise() -
wp-includes/functions.php:
current_time() -
wp-includes/link-template.php:
home_url() -
wp-includes/link-template.php:
day_link -
wp-includes/link-template.php:
user_trailingslashit() -
wp-includes/plugin.php:
apply_filters() -
wp-includes/class-wp-rewrite.php:
WP_Rewrite::get_day_permastruct()
Show 2 more uses
Used By
-
wp-includes/general-template.php:
wp_get_archives() -
wp-includes/general-template.php:
get_calendar() -
wp-includes/canonical.php:
redirect_canonical()
-
Skip to note content
You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note
Contributed by
Codex
Current Day as Link
Returns the URL to the current day’s archive as a link by displaying it within an anchor tag with the PHP echo command.
<a href="<?php echo esc_url( get_day_link( false, false, false ) ); ?>"><?php _e( 'Today’s posts', 'textdomain' ); ?></a>
Use With Variables
PHP code block for use within The Loop: Assigns year, month and day of a post to the variables $arc_year, $arc_month and $arc_day. These are used with the get_day_link() tag, which returns the URL as a link to the daily archive for that post, displaying it within an anchor tag with the PHP echo command. See Formatting Date and Time for info on format strings used in get_the_time() tag.
<?php
$archive_year = get_the_time( 'Y' );
$archive_month = get_the_time( 'm' );
$archive_day = get_the_time( 'd' );
?>
<a href="<?php echo esc_url( get_day_link( $archive_year, $archive_month, $archive_day ) ); ?>">
<?php _e( 'This day’s posts', 'textdomain' ); ?>
</a>
你可能对这些文章感兴趣:
- wordpress函数get_the_posts_navigation()用法示例
- wordpress函数get_the_title()用法示例
- wordpress函数get_the_terms()用法示例
- wordpress函数get_the_tags()用法示例
- wordpress函数get_the_taxonomies()用法示例
- wordpress函数get_the_permalink()用法示例
- wordpress函数get_the_password_form()用法示例
- wordpress函数get_the_posts_pagination()用法示例
- wordpress函数get_the_modified_date()用法示例
- wordpress函数get_the_modified_time()用法示例
- wordpress函数get_the_modified_author()用法示例
- wordpress函数get_the_guid()用法示例
- wordpress函数get_the_ID()用法示例
- wordpress函数get_the_excerpt()用法示例
如有疑问,请前往问答中心反馈!
反馈