具有不同布局的Wordpress循环

具有不同布局的Wordpress循环,wordpress,Wordpress,我想在我的wordpress站点前面运行6篇最新文章的循环,但我想第4篇和第6篇文章的布局与其他4篇稍有不同,我如何在代码中指定这一点 提前感谢。根据需要更改类名 <?php $counter =0; ?> <?php while (have_posts()) : the_post(); ?><!-- begin of loop --> <?php ++$counter; if($counter == 4 or $counter == 6) {

我想在我的wordpress站点前面运行6篇最新文章的循环,但我想第4篇和第6篇文章的布局与其他4篇稍有不同,我如何在代码中指定这一点


提前感谢。

根据需要更改类名

<?php $counter =0; ?>
<?php while (have_posts()) : the_post(); ?><!-- begin of loop -->
<?php
  ++$counter;
  if($counter == 4 or $counter == 6) {
    $postclass = 'class="different"';        
  } else { $postclass = 'normal'; }
?>
<div id="post-<?php the_ID(); ?>" <?php echo $postclass; ?>>
<?php the_content('Read the rest of this entry »'); ?>
</div>
<?php endwhile; ?><!-- end of loop -->


Hi Huntz我实际上需要它有点不同,所以如果是第4个或第6个,则显示不同的图像大小,并显示日期和自定义字段等其他细节,因此我需要的是,如果是第4个或第6个,则显示一组布局项,如果不是,则显示另一组。我知道我可以用CSS做这件事,但我宁愿直接做。谢谢