WordPress文章只显示文章的发布信息,但是文章的更新信息没有显示。他人无法知道这篇文章是否还有效,可信度是否较高。
虽然WorPress自带一个get_the_modified_date()和get_the_modified_time()显示的修改文章的时间。有时候,文章是定时发布的,外后推迟发布的话,会出现修改时间会大于发布时间。这不是想要的。
动手增加修改时间
1.模板页中的content-single.php
中在喜欢的位置添加
<!--?php twentyeleven_updated_on(); ?-->
2.在模板functions.php
中添加以下代码,判断修改时间是否大于发布时间,总之要显示时间大的那个。
if ( ! function_exists( 'twentyeleven_updated_on' ) ) : function twentyeleven_updated_on() { $postDate = strtotime( get_the_date( 'c' ) ); $updateDate = strtotime( get_the_modified_date('c') ); $showTime = $updateDate > $postDate ? $updateDate : $postDate; printf( __( '<div class="last-updated" style="color:grey;font-size:14px"><span class="sep">已更新 </span><time class="entry-date" datetime="%1$s" updatedate>%2$s</time></div>', 'twentyeleven' ), esc_attr(date("c", $showTime)), esc_html(date("Y/m/d", $showTime )) ); } endif;
具体的时间参数可以查看http://codex.wordpress.org/Formatting_Date_and_Time
3.打开文章页面,见文章底部,显示的结果为
已更新 2013/01/31
声明:未经允许禁止转载 东东东 陈煜东的博客 文章,谢谢。如经授权,转载请注明: 转载自东东东 陈煜东的博客
2013 年 2 月 2 日 — 12:37
纯技术博儿呀,欣赏你。能不能交换个链接啥的?(只是我的链接在内页,首页已经满了)
2013 年 2 月 2 日 — 21:55
基本一次成型 不修改
2013 年 2 月 2 日 — 22:45
我有时候总要加点什么东西的。。
2013 年 7 月 24 日 — 16:24
这个东西,有用。