如何在4个帖子后重复循环 时间:2012-10-02 作者:Phife Dawz Possible Duplicate:How to mark every 3rd postStyle every four posts differently 有可能在四个帖子之后重复这个循环吗?(post 5=post 1 css,post 6=post 2 css等)<?php if (have_posts()): while (have_posts()) : the_post(); $count++; if ($count == 1) : ?> <div>Styled post 1</div> <?php elseif ($count == 2) : ?> <div>Styled post 2</div> <?php elseif ($count == 3) : ?> <div>Styled post 3</div> <?php elseif ($count == 4) : ?> <div>Styled post 4</div> <?php else : ?> <?php endif; endwhile; endif; ?> 1 个回复 最合适的回答,由SO网友:Phil Erb 整理而成 假设您只使用计数器来决定要使用的样式,实现所需样式的最简单方法是在$count变量达到4时重置它。<?php elseif ($count == 4) : ?> <div>Styled post 4</div> <?php $count = 0; ?> <?php else : ?> 结束 文章导航