一个二次回路WP_Query()
; 使用循环计数器$query->current_post
从一个数组中输出这五个css类;
示例(基于jzatt的代码):
<?php
$query = new WP_Query(array(
\'post_type\' => \'apps\',
\'posts_per_page\' => 5,
\'meta_key\' => \'_thumbnail_id\'
));
$css_classes = array( \'latest\', \'second\', \'third\', \'fourth\', \'fifth\' ); ?>
<?php if ($query->have_posts()) : ?>
<div id="header">
<?php while ($query->have_posts()) : $query->the_post(); ?>
<div class="<?php echo $css_classes[$query->current_post%5]; ?>_post"> <?php the_post_thumbnail(\'thumbnail\',array(\'class\' => \'class-name\' )); ?> </div>
<?php endwhile; ?>
</div>
<?php endif; wp_reset_postdata(); ?>
调整
\'thumbnail\'
您的特色图像大小;对于6个职位,更改为
posts_per_page\' => 6,
, 再添加一个
\'sixth\'
元素,并更改
$query->current_post%5
到
$query->current_post%6