Pao*_*ina 1 php loops count alternate
我有这个循环,它会计算输出:
while ($wp_query->have_posts()) : $wp_query->the_post(); $current++; $current2++;
Run Code Online (Sandbox Code Playgroud)
然后调用正确的html类我需要这个用于我的设计:
<div class="span4 <?php if($current == 0) { echo 'first'; } elseif($current == 1) { echo 'second'; } elseif($current == 2) { echo 'first'; } elseif($current == 3) { echo 'second'; } ?>" id="<? echo $current; ?>">
Run Code Online (Sandbox Code Playgroud)
的$count从0开始和$count2从1输出应该是这样的:如果0 =第一,1 =秒,2 =第一,3 =第二等等.如何在无限数量的情况下缩短此表达式$count?我希望我的问题很明确.感谢那些在这里帮助我的人.
如果我理解你在这里问的是什么,我想你想用"第一"和"第二"课来替换你的div?
因此,您可以使用%modulo运算符(请参阅http://php.net/manual/en/internals2.opcodes.mod.php)
<div class="span4 <?php echo ($current % 2 === 0 ? 'first' : 'second'); ?>" id="<? echo $current; ?>">
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
120 次 |
| 最近记录: |