返回介绍

get_the_date()

发布于 2017-09-11 00:34:24 字数 3814 浏览 1260 评论 0 收藏 0

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

Retrieve the date on which the post was written.


description

Unlike the_date() this function will always return the date. Modify output with the ‘get_the_date’ filter.


参数

$d

(string) (Optional) PHP date format defaults to the date_format option if not specified.

Default value: ''

$post

(int|WP_Post) (Optional) Post ID or WP_Post object. Default current post.

Default value: null


返回值

(false|string) Date the current post was written. False on failure.


源代码

File: wp-includes/general-template.php

function get_the_date( $d = '', $post = null ) {
	$post = get_post( $post );

	if ( ! $post ) {
		return false;
	}

	if ( '' == $d ) {
		$the_date = mysql2date( get_option( 'date_format' ), $post->post_date );
	} else {
		$the_date = mysql2date( $d, $post->post_date );
	}

	/**
	 * Filters the date a post was published.
	 *
	 * @since 3.0.0
	 *
	 * @param string      $the_date The formatted date.
	 * @param string      $d        PHP date format. Defaults to 'date_format' option
	 *                              if not specified.
	 * @param int|WP_Post $post     The post object or ID.
	 */
	return apply_filters( 'get_the_date', $the_date, $d, $post );
}

更新日志

Versiondescription
3.0.0Introduced.

相关函数

Uses

  • wp-includes/general-template.php: get_the_date
  • wp-includes/functions.php: mysql2date()
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/option.php: get_option()
  • wp-includes/post.php: get_post()

Used By

  • wp-includes/general-template.php: wp_get_document_title()
  • wp-includes/general-template.php: get_the_archive_title()
  • wp-includes/general-template.php: the_date()
  • wp-includes/widgets/class-wp-widget-recent-posts.php: WP_Widget_Recent_Posts::widget()

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 1You must log in to vote on the helpfulness of this note Contributed by Cameron Jones

    All PHP date formats can be found here: http://php.net/manual/en/function.date.php

  2. To make the date appear as “Monday January 11, 2017”, for example, use

    $post_date = get_the_date( 'l F j, Y' ); echo $post_date;

    To make the date appear as “Wed Jan 9”, for example, use

    $post_date = get_the_date( 'D M j' ); echo $post_date;

    To get ISO 8601 date for meta, use

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

    Default Usage

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文