CSSで言うところのfirst-childとlast-child
ただ最近使った記憶がない
//最初・最後 分岐
function isFirst(){
global $wp_query;
return ($wp_query->current_post === 0);
}
function isLast(){
global $wp_query;
return ($wp_query->current_post+1 === $wp_query->post_count);
}
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="entry <?php if(isLast()) echo 'last'; ?>">
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<div class="entry">
<?php the_content(); ?>
</div>
</div>
<?php endwhile; else: ?>
<div class="entry empty">
<p>記事がありません</p>
</div>
<?php endif; ?>
ループの中でifで使う