我给你编了一个简短的例子。应该解释如何在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;