WordPress如何給內容頁添加修改日期,讓文章自動調用到最后一次修改的時間

WordPress如何給內容頁添加修改日期,讓文章自動調用到最后一次修改的時間,讓訪問者知道你的文章是最近更新過的。效果如下:

實現(xiàn)方法:打開主題目錄下的functions.php文件,在最后添加下面代碼:

//文章最后更新時間
function show_last_updated( $content ) {
$u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');
if ($u_modified_time >= $u_time + 86400) {
$updated_date = get_the_modified_time('Y-m-j');
$updated_time = get_the_modified_time('h:s');
$custom_content .= '<p class="last-updated-date">本文于 '. $updated_date . '  '. $updated_time .'更新,部分內容具有時效性,如有失效,請留言。</p>';
}
$custom_content .= $content;
return $custom_content;
}
add_filter( 'the_content', 'show_last_updated' )

如圖所示:

然后在你頁面樣式文件里加入下面樣式:

.last-updated-date {
    background-color: #fffbe5;
    border: 1px solid #f5e295;
    color: #de9e0e;
    border-radius: 6px;
    font-size: 14px;
    margin-bottom: 20px;
    padding: 10px 20px
}

.last-updated-date a {
    color: #b98000
}

.last-updated-date a:hover {
    color: #926500
}

保存,刷新,結束。

 

THE END
亚洲中文色欧另类欧美,久久久久久久激情,亚洲 日韩 欧美 另类 国产,中文字幕高清无码男人的天堂 www.sucaiwu.net