I need to create the following ul after the creation of 5 li , and ul to continue to create li in ul . Only ul should be all on the same level. Here is the code, CMS OpenCart.

 <?php foreach (array_chunk($category['children'], ceil(count($category['children']) / $category['column'])) as $children) { ?> <div class="children clearfix"> <ul class="children-list children-list-col clearfix"> <?php $k=0; foreach ($children as $child) {(($k%5==0) ? "</ul><ul>" :"");?> <li> <a class="link" href="<?php echo $child['href']; ?>" > <img class="thumb" src="<?php echo $child['thumb']?>" width="40" height="40" alt="" /> <span class="text"><?php echo $child['name']; ?></span></a> </li> <?php } ?> </ul> </div> <?php } ?> 

Perhaps there is another solution, thanks in advance!

UPD: With this code, it gives an error which is written in the header.

 <?php foreach ($children as $child) {(($k%5==0) ? echo "</ul><ul>" : echo"");?> 

UPD: On some basis, the code <?php $k=0; foreach ($children as $child) { if($k%5==0) { echo "</ul><ul>"; } $k++;?> <?php $k=0; foreach ($children as $child) { if($k%5==0) { echo "</ul><ul>"; } $k++;?> <?php $k=0; foreach ($children as $child) { if($k%5==0) { echo "</ul><ul>"; } $k++;?> , which shows signs of efficiency, thanks tCode , does not quite work as I need .. I have been suffering with this for 2 days already, of course, because of not knowing ..

 <div class="children clearfix"> <ul class="children-list children-list-col clearfix"> </ul><ul> <li> <a class="link" href="http://rumishop2/component/cmp23" > <img class="thumb" src="http://rumishop2/image/cache/no_image-100x100.png" width="40" height="40" alt="" /> <span class="text">Components</span></a> </li> <li> <a class="link" href="http://rumishop2/component/PC123" > <img class="thumb" src="http://rumishop2/image/cache/no_image-100x100.png" width="40" height="40" alt="" /> <span class="text">PC</span></a> </li> <li> <a class="link" href="http://rumishop2/component/mouse" > <img class="thumb" src="http://rumishop2/image/cache/no_image-100x100.png" width="40" height="40" alt="" /> <span class="text">Mice and Trackballs</span></a> </li> <li> <a class="link" href="http://rumishop2/component/monitor" > <img class="thumb" src="http://rumishop2/image/cache/no_image-100x100.png" width="40" height="40" alt="" /> <span class="text">Monitors</span></a> </li> <li> <a class="link" href="http://rumishop2/component/printer" > <img class="thumb" src="http://rumishop2/image/cache/no_image-100x100.png" width="40" height="40" alt="" /> <span class="text">Printers</span></a> </li> </ul><ul> <li> <a class="link" href="http://rumishop2/component/scanner" > <img class="thumb" src="http://rumishop2/image/cache/no_image-100x100.png" width="40" height="40" alt="" /> <span class="text">Scanners</span></a> </li> <li> <a class="link" href="http://rumishop2/component/web-camera" > <img class="thumb" src="http://rumishop2/image/cache/no_image-100x100.png" width="40" height="40" alt="" /> <span class="text">Web Cameras</span></a> </li> </ul> </div> 

This is the source code of Ctrl + U, I mean ... As you can see .. What the code creates every 5 times, but firstly, they are not at level 1 with <ul class="children-list children-list-col clearfix"> , and inside it .. And on top of that, for some reason, they are still created in the main page. Please help and have mercy ..

  • Did you make the menu yourself? - user33274
  • Well, something like that .. I looked at another site, they have Yul created there, but this is definitely not css and not js. - Kirill Xiaomi
  • roll it up on your desktop without php, see how it will be, and then embed php code but on a local server, ie optimize it on the installed OcStore it is also OpenCard - user33274
  • what do you think this construct does (($k%5==0) ? "</ul><ul>" :""); ? - Dmitriy Simushev 1:16 pm
  • Oh, there echo should stand .. Well, I explained to you that I need to create a new ul every Kirill Xiaomi

1 answer 1

Replace:

 <?php $k=0; foreach ($children as $child) {(($k%5==0) ? "</ul><ul>" :"");?> 

On:

 <?php $k=0; foreach ($children as $child) { if($k%5==0) { echo "</ul><ul>"; } $k++;?> 
  • Do not rob .. Parse error: syntax error, unexpected '}', expecting ',' or ';' in - Kirill Xiaomi
  • Everything corrected .. Trying to achieve now what I want. - Kirill Xiaomi
  • Now I will try - Kirill Xiaomi
  • Now it works, thanks ..) - Kirill Xiaomi
  • But I could not fix that code completely .. Because the picture looks like this .. - Kirill Xiaomi