index.phpに3日以内に投稿された記事のタイトルに「New」の文字を付ける方法をご紹介します。
index.php
<?php
$post_time = get_the_time('U');
$days = 3;
$last = time() - ($days * 24 * 60 * 60);
if ($post_time > $last) {
echo '<span class="new_post">NEW</span>';
}
?>
$days の部分を変えると日数を変更することが出来ます。
ちなみにこちらは直接「New」という文字を出力していますが、日に頻繁に更新する人は「New」の文字が多くなってしまいますので、僕は:afterでCSSで付け加えています。
index.php
<?php
$post_time = get_the_time('U');
$days = 3;
$last = time() - ($days * 24 * 60 * 60);
if ($post_time > $last):
?>
<h2 class="new_post"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
<?php else: ?>
<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
<?php endif; ?>
CSS
h2.new_post:after{
content: "New";
padding-left: 6px;
}

