get_the_date() - WordPress 函数参考中文文档

返回介绍

get_the_date()

发布于 2017-09-11 字数3816 浏览 966 评论 0

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

Retrieve the date on which the post was written.


描述

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 );
}

更新日志

Version 描述
3.0.0 Introduced.

相关函数

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>
    
    

上一篇:get_the_content_feed()

下一篇:get_the_excerpt()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!