样式一

1、在WordPress主题中 functions.php 文件中添加以下代码:

//文章显示最后更新时间 
function dujin_post_update( $content ) {
$u_time = get_the_time('U'); 
$u_modified_time = get_the_modified_time('U'); 
$custom_content = ''; 
if ($u_modified_time >= $u_time + 86400) {
$updated_date = get_the_modified_time('Y-m-d日'); //这里设置时间显示格式,可自由调整。
$custom_content .= '<p class="dujin-update">本文最后更新于<code>'. $updated_date . '</code>,因文章时效性,若有错误或相关图文已失效,请在下方留言或联系<a href="http://wpa.qq.com/msgrd?v=3&uin=3387285338&site=qq&menu=yes"><b>发稿者</b></a>。</p>';  
} 
    $custom_content .= $content;
    return $custom_content;
}
add_filter( 'the_content', 'dujin_post_update' );

其中86400就是秒数,意思是超过24小时才显示最后更新时间,这个时间可以根据自己的需求去制定。到这里,文章最近的编辑时间就能自动添加了。

2、添加CSS文件

如果想要实现本文章顶部展现颜色和边框的效果,还需要设置下CSS,代码如下:

//文章显示最后更新时间 
.dujin-update{padding:10px 20px;background-color:#FEEFB3;border-radius:6px;border:1px solid;font-size:14px;text-align:left}

想要这个代码生效,理论上可以直接添加到主题的CSS样式文件中,或者单独建一个CSS文件到网站。

样式二

1、 functions.php 文件中添加以下代码:

//文章显示最后更新时间
function wpb_last_updated_date( $content ) {
$u_time = get_the_time('U'); 
$u_modified_time = get_the_modified_time('U'); 
$custom_content = ''; 
if ($u_modified_time >= $u_time + 86400) { 
$updated_date = get_the_modified_time('Y.m.d');
$updated_time = get_the_modified_time('h:i  因文章时效性,若有错误或相关图文已失效,请在下方留言。'); 
$custom_content .= '<p class="last-updated">本文最后更新于 '. $updated_date . '  '. $updated_time .'</p>';  
} 
 
    $custom_content .= $content;
    return $custom_content;
}
add_filter( 'the_content', 'wpb_last_updated_date' );

2、添加CSS文件

/* 文章显示最后更新时间开始
.last-updated {
    color: #db7c22;
background: #fff4b9;
border: 1px solid #eac946;
overflow: hidden;
margin: 10px 0;
padding: 15px 15px 15px 35px;
font-size: 14px;
}
历史上的今天
12月
1
    抱歉,历史上的今天作者很懒,什么都没写!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。