当前浏览:首页 / WordPress函数 / get_the_date()

get_the_date( string $format = '', int|WP_Post $post = null )

检索文章的撰写日期

datemore...

themore...


描述

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开始引入

使用示例

  • 示例1

    要获取元数据的ISO 8601日期,请使用

    <time datetime="<?php echo get_the_date('c'); ?>" itemprop="datePublished"><?php echo get_the_date(); ?></time>
  • 示例2

    所有PHP日期格式都可以在这里找到:http://php.net/manual/en/function.date.php

  • 示例3

    例如,要使日期显示为“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;
  • 示例4

    获取日期格式,格式为天、日符号、短月和长年
    例如 15th Jan 2020

    get_the_date( 'dS M Y', $post->ID )
    
    
  • 示例5

    默认用法

    <span class="entry-date"><?php echo get_the_date(); ?></span>
    
    
  • 示例6

    如果要以Ymd格式显示发布日期(例如:20191231):

    <?php 
    $post_date = get_the_date( 'Ymd' );
    echo $post_date;
    ?>
  • 示例7

    如果你想显示当月的全名和年份,那么你可以使用它
    例如 January 2020

    get_the_date( 'F Y', get_the_ID() );
  • 示例8

    如果需要ISO格式的模式修改日期

    <?php echo get_the_modified_date( 'c' ); ?>