使用模量php检测每个4 [英] Detect each 4 using modulus php
本文介绍了使用模量php检测每个4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里是一个简单的例子,它是一个简单的例子。
<?php if(have_posts()):?>
<?php $ count = 0;?>
<?php while(have_posts()):the_post(); >
< div class =column>
<! - content - >
< / div>
<?php
if($ count%4 == 0){
echo'< div class =clear>< / div>';
}
$ count ++;
?>
<?php endwhile; >
<?php endif; >
。我做错了什么?谢谢。
解决方案
你需要在1开始计数,因为你在循环结束时增加: / p>
<?php $ count = 1;?>
或者,在循环开始/检查前增加它:
<?php
$ count ++;
if($ count%4 == 0){
echo'< div class =clear>< / div>';
}
?>
I am trying to detect each 4th post to insert extra code in my layout in wordpress using modulus method but I just cant get it.
Here is a short example of mine:
<?php if (have_posts()) : ?>
<?php $count=0;?>
<?php while (have_posts()) : the_post(); ?>
<div class="column">
<!--content-->
</div>
<?php
if ($count % 4 == 0){
echo '<div class="clear"></div>';
}
$count++;
?>
<?php endwhile; ?>
<?php endif; ?>
all that is inside the while loop. What am I doing wrong? Thank you.
解决方案
You need to start your counter at 1, as you are increasing it at the end of the loop:
<?php $count=1;?>
Either that, or you increase it at the start of the loop / before the check:
<?php
$count++;
if ($count % 4 == 0){
echo '<div class="clear"></div>';
}
?>
这篇关于使用模量php检测每个4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文