我为您编写了一个简短的小示例。应该说明如何在WP循环中获取第一条和最后一条帖子。
$post_count = 0;
$total = count($posts);
while (have_posts()) : the_post();
if ($post_count == 1 AND $post_count !== $total)
{
// This is the first post
}
if ($post_count == $total)
{
// This is the last item
}
$post_count++;
endwhile;