新着記事に“NEW!”を表示するようPHPを設定。
//新着記事にNEW
add_filter('the_title', function($title, $id) {
// 表示期間3日
$days = 3;
if (get_post_type($id) == 'post') {
// 現在の時刻取得
$now = date_i18n('U');
// 投稿ページの投稿日時取得
$post_time = get_the_time('U',$id);
// NEW表示期間
$last = $now - ($days * 24 * 60 * 60);
if ($post_time > $last) {
$title = $title . '<span class="new-txt">NEW!</span>';
}
}
return $title;
}, 20, 2);
新着“NEW!”のデザイン設定。
.new-txt{
content: "NEW!";
text-shadow: none;
font-family: 'Shin Maru Go Regular';
margin-left: .2em;
padding: 1px 2px;
vertical-align: top;
font-size: .6rem;
color: #fff;
border-radius: 3px;
background-color: crimson;
}