Answer the question
In order to leave comments, you need to log in
How to assign classes to loop elements?
I have a list that looks like this:
<?php if(count($items)): ?>
<ul>
<?php foreach ($items as $key=>$item): ?>
<li class="someclass myclass">some content</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Answer the question
In order to leave comments, you need to log in
$class = array('class-one', 'class-red', 'class-rounded');
<li class="someclass <?php echo $class[$key]; ?>">some content</li>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question