the_modified_time()显示当前文章/页面的最终修改时间

目录

描述

This tag displays the time (and date) a post was last modified and is similar to the functionality of the_time(), which displays the time (and date) a post was created. This tag must be used within The Loop. If no format parameter is specified, the Default date format (please note that says Date format) setting from Administration > Settings > General is used for the display format.

If the post or page is not yet modified, the modified time is the same as the creation time.

If you want to display both the modified time and the creation time, you may want to use an if statement (e.g. if (get_the_modified_time() != get_the_time())) to avoid showing the same time/date twice.

Use get_the_modified_time() to retrieve the value.

the_modified_time() 描述

用法

 <?php the_modified_time$d ); ?> 

the_modified_time() 用法

参数

d

(string) (可选) The format the date is to display in. Defaults to the date format configured in your WordPress options. See Formatting Date and Time.

默认值: F j, Y

the_modified_time() 参数

示例

Default Usage

Displays the time (date) the post was last modified, using the Default date format setting (e.g. F j, Y) from Administration > Settings > General.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
<p>Last modified: <?php the_modified_time(); ?></p>
Last modified: December 2, 2006

Time in the 12-hour format (am/pm)

If a post was modified at 10:36pm, this example displays the time the post was last modified using the 12-hour format parameter string 'g:i a'.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
<p>Time last modified: <?php the_modified_time('g:i a'); ?></p>
Time last modified: 10:36 pm

Time in the 24-hour format

If a post was modified at 10:36pm, this example displays the time the post was last modified using the 24-hour format parameter string 'G:i'.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
<p>Time last modified: <?php the_modified_time('G:i'); ?></p>
Time last modified: 22:36

Date as Month Day, Year

Displays the last modified time and date in the date format 'F j, Y' (ex: December 2, 2006), which could be used to replace the tag the_modified_date().

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
<div>Last modified: <?php the_modified_time('F j, Y'); ?></div>
Last modified: December 2, 2006

Date and Time

Displays the date and time.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
<p>Modified: <?php the_modified_time('F j, Y'); ?> at <?php the_modified_time('g:i a'); ?></p>
Modified: December 2, 2006 at 10:36 pm

the_modified_time() 示例

历史

添加于 版本: 2.0.0

the_modified_time() 历史

源文件

the_modified_time() 函数的代码位于 wp-includes/general-template.php

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Display the time at which the post was last modified.
 *
 * @since 2.0.0
 *
 * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
 */
function the_modified_time($d = '') {
	/**
	 * Filter the localized time a post was last modified, for display.
	 *
	 * @since 2.0.0
	 *
	 * @param string $get_the_modified_time The formatted time.
	 * @param string $d                     The time format. Accepts 'G', 'U',
	 *                                      or php date format. Defaults to value
	 *                                      specified in 'time_format' option.
	 */
	echo apply_filters( 'the_modified_time', get_the_modified_time($d), $d );
}

the_modified_time() 源文件

相关