Z
Z
z_u_q2018-05-23 23:35:13
PHP
z_u_q, 2018-05-23 23:35:13

How to display information in four columns?

In the footer, you need to display 3 columns footer-top__list with four li. I tried to do it like this, but for some reason each li is wrapped in footer-top_list. What's wrong? Please help to implement menu display in three columns.

<?$d = ceil(count($arResult["TEXT"])/3);
$i = 0;  
?><ul class="footer-top__list"><?
foreach($arResult as $arItem) 
{ 
      if( $i > 0 && $i%$d == 0) {?></ul><ul class="footer-top__list"><?} 
      ?><li><a href="<?=$arItem["LINK"]?>"><?=$arItem["TEXT"]?></a></li><?
      $i++;
} 
?></ul><? ?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anatoly Kryanga, 2018-05-24
@z_u_q

Try

<? $n = count($arResult["TEXT"]);
$d = ceil($n / 4);
$n--;
$i = 0; ?>
<ul class="footer-top__list">
    <? foreach($arResult as $arItem) { ?>
        <li><a href="<?= $arItem["LINK"] ?>"><?= $arItem["TEXT"] ?></a></li>
        <? if( $i%$d == 0 && $i > 0 && $i < $n) {?>
            </ul><ul class="footer-top__list">
        <?}
        $i++;     
    } ?>
</ul>

P
Pavel Kornilov, 2018-05-24
@KorniloFF

<?$d = ceil(count($arResult["TEXT"])/3);
$i = 0;  
?><ul class="footer-top__list"><?
foreach($arResult as $arItem) 
{ 
      ?><li><a href="<?=$arItem["LINK"]?>"><?=$arItem["TEXT"]?></a></li><?
      $i++;
} 
?></ul><? ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question