Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try this one.</p> <pre><code>&lt;div id="content"&gt; &lt;div class="content-column"&gt; &lt;?php $cols = 3; // Change to columns needed. $catcount = count($categories); $catpercol = ceil($catcount / $cols); $c = 0; foreach ($categories as $category) { if ( $c == $catpercol ) { $c = 0; print "&lt;/div&gt;&lt;div class='content-column'&gt;"; } ?&gt; &lt;div class="manufacturer-list"&gt; &lt;div class="manufacturer-heading"&gt;&lt;?php echo $category['name']; ?&gt;&lt;a id="&lt;?php echo $category['name']; ?&gt;"&gt;&lt;/a&gt;&lt;/div&gt; &lt;div class="manufacturer-content"&gt; &lt;?php if ($category['manufacturer']) { ?&gt; &lt;?php for ($i = 0; $i &lt; count($category['manufacturer']);) { ?&gt; &lt;ul&gt; &lt;?php $j = $i + ceil(count($category['manufacturer']) / 4); ?&gt; &lt;?php for (; $i &lt; $j; $i++) { ?&gt; &lt;?php if (isset($category['manufacturer'][$i])) { ?&gt; &lt;li&gt;&lt;a href="&lt;?php echo $category['manufacturer'][$i]['href']; ?&gt;"&gt;&lt;?php echo $category['manufacturer'][$i]['name']; ?&gt;&lt;/a&gt;&lt;/li&gt; &lt;?php } ?&gt; &lt;?php } ?&gt; &lt;/ul&gt; &lt;?php } ?&gt; &lt;?php } ?&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php $c++; } ?&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>Add <code>.content-column { float: left; width: 33.33333%; }</code> to your CSS.</p> <p>Details: <code>$cols = 3;</code> enables you to set the desired number of columns (note: you might need to change CSS accordingly).</p> <p><code>$catcount = count($categories);</code> gives you the total number of categories about to be rendered.</p> <p><code>$catpercol = ceil($catcount / $cols);</code> divides that total number evenly into the required number of columns with the last column having eventually less items than the others.</p> <p><code>$c = 0;</code> is your counter. It increases at the end of the outer foreach loop.</p> <p>Within the loop, <code>$c</code>is checked if it matches the <code>$catpercol</code> number and if so, the current parent div is closed and a new one created. You end up with as many parent divs as you need columns. Just add appropiate CSS to make them appear besides each other.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload