[英]add a </tr><tr> automatically after every 4 <td>
I have below script which add after every 2 , now what i want is make this script to work after every 4我有下面的脚本,它在每 2 个之后添加,现在我想要的是让这个脚本在每 4 个之后工作
right now i'm showing 2 images per row, i want to make it 4 images per row & then new line should start.现在我每行显示 2 张图像,我想每行显示 4 张图像,然后应该开始新的一行。
what i want我想要的是
Row 1 - 1,2,3,4 Row 2 - 5,6,7,8第 1 行 - 1,2,3,4 第 2 行 - 5,6,7,8
any idea?任何的想法?
<table class="views-view-grid cols-4">
<tbody>
<?php
if( have_rows('picture') ):
echo "<tr>";
$currentCount = -1;
while ( have_rows('picture') ) : the_row();
{
//echo "<td>";
?>
<td>
<img typeof="foaf:Image" src="<?php the_sub_field('image');?>" width="220" height="220" alt="">
</td>
<?php
//echo"</td>";
$currentCount = ($currentCount + 1) % 2;
if($currentCount == 1)
{
echo '</tr><tr>';
}
}
endwhile;
else :
// no rows found
endif;
?>
</tbody>
</table>
Use $currentCount
as a counter variable and have it incremented in each iteration of while()
loop.使用
$currentCount
作为计数器变量,并在while()
循环的每次迭代中递增。 Also, you need to change the inner if
condition accordingly.此外,您需要相应地更改内部
if
条件。
<table class="views-view-grid cols-4">
<tbody>
<?php
if( have_rows('picture') ):
echo "<tr>";
$currentCount = 1;
echo '<tr>';
while ( have_rows('picture') ) :
the_row();
?>
<td>
<img typeof="foaf:Image" src="<?php the_sub_field('image');?>" width="220" height="220" alt="">
</td>
<?php
if($currentCount % 4 == 0){
echo '</tr><tr>';
}
++$currentCount;
endwhile;
echo '</tr>';
else :
// no rows found
endif;
?>
</tbody>
</table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.