最新3件の投稿に「New」を付ける

<ul class="custom-list">
<?php
	$posts= get_posts( 'post_type=post&posts_per_page=9&order=desc' );
	
	foreach ( $posts as $key=> $post ) {
		setup_postdata($post);
		$attribute_before= $key < 3 ? 'new' : '';
?>
	<li>
		<article id="post-<?php the_ID(); ?>" <?php post_class( $attribute_before ); ?>>
		<?php the_title('<h3 class="entry-title">','</h3>');?>
		</article>
	</li>
<?php
	}
	wp_reset_postdata();
?>
</ul>

https://ja.wordpress.org/support/topic/%E3%82%AB%E3%82%B9%E3%82%BF%E3%83%A0%E6%8A%95%E7%A8%BF%E3%82%BF%E3%82%A4%E3%83%97%E3%81%AE%E6%9C%80%E6%96%B03%E4%BB%B6%E3%81%ABnew%E3%82%92%E8%A1%A8%E7%A4%BA%E3%81%95%E3%81%9B%E3%81%9F%E3%81%84/

Raindrops テーマのnew 表示

Raindropsテーマでも、最新投稿に「new」表示を行うようにデフォルトで設定されています。

post_class()にクラスを追加するのは、同じですがRaindropsの場合は、以下のように経過時間によって表示非表示をコントロールしています。

$raindrops_now			= current_time( 'timestamp' );
$raindrops_publish_time	= get_the_time( 'U' );
$raindrops_modified_time= get_the_modified_time( 'U' );
$raindrops_period		= apply_filters( 'raindrops_new_period', 3 );
$raindrops_Period		= 60 * 60 * 24 * $raindrops_period;

if ( $raindrops_now < $raindrops_Period + $raindrops_publish_time ) {

	$classes[]= 'raindrops-pub-new ';
}

if ( $raindrops_now < $raindrops_Period + $raindrops_modified_time ) {

	$classes[]= 'raindrops-mod-new';
}
[emulsion_relate_posts]