Arkheの新着記事7日以内の記事カードにNEWマークを付けてみました

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;
}

以上です~。

高速・安心のWebサイト運営なら
Hostingerで決まり!

WordPressも秒速でインストール。高性能・低価格で、個人からビジネスまで幅広く対応します。

公式サイトを見る

Author