query_posts
应仅用于主回路。相反,请使用WP_Query
类别:
$my_query = new WP_Query( array(
\'post_type\' => \'post\',
\'posts_per_page\' => 10,
\'order\' => \'DESC\',
\'paged\'=> $paged
) );
echo \'<ul>\';
while ( $my_query->have_posts() ) : $my_query->the_post();
if ( $my_query->current_post > 0 && ( $my_query->current_post + 1 ) % 6 == 0 ) {
echo "<li>I\'m odd one</li>";
} else {
echo "<li>" . get_the_title() . "</li>";
}
endwhile;
echo \'</ul>\';
以上每六个元素都会“做特殊的事情”。如果你只想把它放在第六个
$my_query->current_post == 5
相反(索引从0开始)。