I have the following PHP loop:
if( have_rows('home_projecten') ) {
$i = 0;
while( have_rows('home_projecten') ) {
$i++;
the_row();
if($i == 1) {
echo '<div class="slide">';
}
echo '<div class="project"></div>';
if($i == 3) {
$i = 0;
echo '</div>';
}
}
}
I am trying to split my 'project items' in slides, with 3 items per slide. Currently, this is working fine for every 'full' slide, meaning a slide with 3 projects. When $i
becomes larger than 3, a new slide is added.
However, when I have for example 4 projects, the second slide div is not closed anymore, as I never reach $i == 3
again.. I know I could fix this with counting the array and doing something with that, but I have no idea how..
Help would be greatly appreciated!
My Answer:
Page 1: Project 1'; } elseif($i == 2) { echo 'Page 2: Project 2'; } elseif($i == 3) { echo 'Page 3: Project 3'; } $i++; }}
This loop is iterating over the rows of a repeater field called 'home_projecten' and displaying the projects on different pages based on the value of $i. Each time the loop runs, $i is incremented by 1 and the corresponding project is displayed based on the value of $i.
You can continue this pattern to display more projects on different pages by adding more elseif statements for each project.
Rate this post
3 of 5 based on 2322 votesComments