$i = 0; foreach($this->items as $item) { //делаем пост-инкремент и сравниваем значение if (++$i==7) { echo "<div>Я тот блок, который будет выведен после 6 элемента, то есть буду седьмым </div>"; } }
We talked to you in the comments and you reported that are not familiar with PHP, I will tell in more detail about your problem solution.
Your code essentially looks at the first condition that there are some items in the this-items array (the size of the array is greater than 0), and if so, displays a div with the class: tagItemList, after which the array of $ this-> items starts sequentially .
<?php if(count($this->items)): ?> //условие <div class="tagItemList"> //вывод элемента <?php foreach($this->items as $item): ?> //перебор массива
Your script uses an alternative method for defining control structures, which you can read about here . In each case, the main form of the alternative syntax is to change the opening brace to a colon (:), and the closing bracket to endif ;, endwhile ;, endfor ;, endforeach; or endswitch; respectively.
Consequently, your task is to iterate over the elements of the items array and display a div on element 7. And so, for starters, check whether this condition will work for you.
<?php if(count($this->items)): ?> <div class="tagItemList"> <?php $i = 0; foreach($this->items as $item): $i++; echo "i = ".$i." "; ?>
The condition will work if you have i = 7 in the code, then below you can insert the code that will output the required div (and thanks to this you can determine which boundary i will be displayed)
<?php if(count($this->items)): ?> <div class="tagItemList"> <?php $i = 0; foreach($this->items as $item): if (++$i==7): echo "<div>1</div>"; endif; ?>
This option of checking variables is the easiest, although of course for debugging, use various extensions that help monitor the progress of the program.