获取wordpress文章最后修改时间的代码函数

WordPress教程 2908

默认情况下,wordpress文章发布时间都是第一次发布时间发准,无论之后修改与否,文章调用显示的均是第一次发布时间。对于有特别需求的wordpress博主可能需要调用wordpress文章最后修改时间,wordpress默认的日期调用代码显然不能满足需求,因此需要另外的代码获取wordpress最后修改日期时间。

WordPress最后更新时间的函数是:the_modified_time(),调用函数:

1
<?php the_modified_time('Y年n月j日'); ?>

完整代码一:

1
2
3
4
5
6
7
8
9
<?php 
	$u_time = get_the_time('U');
	$u_modified_time = get_the_modified_time('U');
	if ($u_modified_time != $u_time) {
		the_modified_time('Y年n月j日');
	} else {
		the_time('Y年n月j日');
	}
?>

完整代码二:

1
2
3
4
5
<?php if ((get_the_modified_time('Y')*365+get_the_modified_time('z')) > (get_the_time('Y')*365+get_the_time('z'))) : ?>
最后修改:<?php the_modified_time('Y-m-j h:s'); ?>
<?php else : ?>
<?php the_date_xml(); ?>
<?php endif; ?>

以上两种完整代码任选其一,代码大意:如果文章有修改,则调用最后修改时间,没有修改,则显示第一次发布时间

精品推荐: