Answer the question
In order to leave comments, you need to log in
How to display blocks in a column?
Now the score goes like this
1 2 3
4 5 6
It should be like this:
1 3 5
2 4 6
<?php if ($categories) { ?>
<div class="list">
<?php foreach ($categories as $category) { ?>
<ul>
<li>
<a href="<?php echo $category['href']; ?>">
<img src="<?php echo $category['thumb']; ?>" title="<?php echo $category['name']; ?>" alt="<?php echo $category['name']; ?>" />
<span><?php echo $category['name']; ?></span>
</a>
</li>
<div class="clear"></div>
</div>
<?php } ?>
<?php } ?>
Answer the question
In order to leave comments, you need to log in
Because the algorithm is not very clear, but judging by the comments, it should be displayed in vertical blocks. I can't check, but something like this.
And try to ask the right questions.
<?php if ($categories) : ?>
<div class="list">
<ul><li>
<?php
$cols = 2; // число колонок
$view = ceil( count($categories) / $cols );
$counter = 0;
foreach ($categories as $category) : ?>
<div>
<a href="<?php echo $category['href']; ?>">
<img src="<?php echo $category['thumb']; ?>" title="<?php echo $category['name']; ?>" alt="<?php echo $category['name']; ?>" />
<span><?php echo $category['name']; ?></span>
</a>
</div>
<?php
$counter++;
if( $counter == $view) {
echo "</li><li>";
$counter = 0;
?>
<?php endforeach; ?>
</li></ul>
</div>
<?php endif; ?>
Fill in the first line with a cycle from 1 with a step of 2, the second - from 2 with a step of 2.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question