WordPressテーマArkheの新着記事7日以内の記事カードにNEWマークを付けてみました。
こちらが参考です。
add_action(
'arkhe_pre_get_part__post_list/item/meta/times',
function() {
// 記事の投稿日を取得
$post_date = get_the_date('Y-m-d');
$current_date = date('Y-m-d');
// 日付を比較して7日以内ならNEWマークを表示
$diff = strtotime($current_date) - strtotime($post_date);
$days_diff = floor($diff / (60 * 60 * 24));
if ($days_diff <= 7) {
echo '<span class="new-mark">NEW</span>';
}
}
);
add_action() を使って arkhe_pre_get_part__post_list/item/meta/times のフックを利用。
get_the_date(‘Y-m-d’) で 記事の投稿日 を取得。
現在の日付と比較 し、7日以内なら NEW マークを出力。
CSS
.new-mark {
color: red;
font-weight: bold;
background-color: yellow;
padding: 2px 6px;
border-radius: 3px;
font-size: 12px;
margin-right: 5px;
}
以上です~。