描述
与the_date()不同,此函数将始终返回日期。使用‘get_the_date’过滤器修改输出。
参数
- $format
-
(string)(可选) PHP日期格式。默认为'date_format'选项。
默认值: ''
- $post
-
(int|WP_Post)(可选) Post ID或WP_Post对象。默认当前文章。
默认值: null
返回
(string|int|false) 当前文章的撰写日期。失败时为False。
源码
更新日志
版本 | 描述 |
---|---|
3.0.0 | 开始引入 |
使用示例
要获取元数据的ISO 8601日期,请使用
<time datetime="<?php echo get_the_date('c'); ?>" itemprop="datePublished"><?php echo get_the_date(); ?></time>
所有PHP日期格式都可以在这里找到:http://php.net/manual/en/function.date.php
例如,要使日期显示为“Monday January 11, 2017”,请使用
$post_date = get_the_date( 'l F j, Y' ); echo $post_date;
例如,要使日期显示为“Wed Jan 9”,请使用
$post_date = get_the_date( 'D M j' ); echo $post_date;
获取日期格式,格式为天、日符号、短月和长年
例如 15th Jan 2020get_the_date( 'dS M Y', $post->ID )
默认用法
<span class="entry-date"><?php echo get_the_date(); ?></span>
如果要以Ymd格式显示发布日期(例如:20191231):
<?php $post_date = get_the_date( 'Ymd' ); echo $post_date; ?>
如果你想显示当月的全名和年份,那么你可以使用它
例如 January 2020get_the_date( 'F Y', get_the_ID() );
如果需要ISO格式的模式修改日期
<?php echo get_the_modified_date( 'c' ); ?>