方法3.使用代码添加旧的帖子通知

Discuss my database trends and their role in business.
Post Reply
shaownhasane
Posts: 63
Joined: Mon Dec 23, 2024 2:26 pm

方法3.使用代码添加旧的帖子通知

Post by shaownhasane »

1
2
3
4
5
6
7
p.post-modified-info {
background: #fbffd8;
padding: 10px;
border: 1px solid orange;
font-size: small;
font-weight: bold;
}
由WPCode与 主办
在 WordPress 中一键使用
此方法需要手动将代码添加到您的 WordPress 主题文件中。如果您以 香港电报数据 前从未执行过此操作,请查看我们有关如何在 WordPress 中添加自定义代码片段的指南。

只需将以下代码复制并粘贴到主题的 single.php 模板中即可。


// Define old post duration to one year
$time_defined_as_old = 60*60*24*365;

// Check to see if a post is older than a year
if((date('U')-get_the_time('U')) > $time_defined_as_old) {

$lastmodified = get_the_modified_time('U');
$posted = get_the_time('U');

//check if the post was updated after being published
if ($lastmodified > $posted) {

// Display last updated notice
echo '<p class="old-article-notice">This article was last updated ' . human_time_diff($lastmodified,current_time('U')) . ' ago</p>';

} else {
// Display last published notice
echo '<p class="old-article-notice">This article was published ' . human_time_diff($posted,current_time( 'U' )). 'ago</p>';
Post Reply