I ran into a problem. I built the foreach in PHP:
<?php $show = false; ?> <?php foreach ($this->items as $item) : ?>
But I want to repeat the first 20 points and continue the next 16 elements.
I managed to take a break after 20 points, but I do not get the next 16 elements (starting from number 21).
This is what I have so far:
<?php $show = false; ?> <?php $i = $item->id = 1; ?> <?php foreach ($this->items as $item) : ?> <?php if(++$i > 20) break; ?>
If I set $i to '21' , it still displays element 1, etc.
Solution ## Thanks @dhavald
<?php $show = false; ?> <?php foreach (array_slice ($this->items, 0, 20) as $item) : ?>
By placing array_slice in foreach, you can control the elements you want to show. So, on the next div I want to show items 21 to 36, the only thing I needed to change was 0 and 20 in, 20, 36
To clarify what I'm looking for, I have three divs where I want to repeat some elements on it. If the user dumps the div on the first, the first 20 elements will appear, and if the user clicks on div2, the next 16 elements will appear.
How can I fix this code to make this happen?
As I forgot to mention, the solutions you brought helped me understand the process, but since I used the component generator for Joomla 3.1, there is one line of code that makes it a little more complicated to call the first 20 and second 16 items.
Right after the foreach loop there is this line of code
if($item->state == 1 || ($item->state == 0 && JFactory::getUser()>authorise('core.edit.own',' com_ncitycatemus.vraagantwoordtoevoegen.'.$item->id))): $show = true;
How can I control it than using a loop? Or do you suggest another way?
Thanks in advance! Really helped me understand the cycle!