0

I want to add a specific div after every 3 items inside the category list. So I want to extend the code of /app/design/frontend/theme/theme/template/catalog/product/list.phtml

There is the following code that displays every product inside the category:

How can I extend this code and add a specific div after every 3 items, so I get something like this:

<div class="item-1"></div>
<div class="item-2"></div>
<div class="item-3"></div>
<div class="new-to-added-div"></div>
<div class="item-4"></div>
<div class="item-5"></div>
<div class="item-6"></div>
<div class="new-to-added-div"></div>
0

2 Answers 2

1

You should use the Modulo operator % :

<?php $i = 0; foreach ($_productCollection as $_product): ?>
<?php if($i > 0 && $i%3 == 0): ?>
     <div class="new-to-added-div"></div>
<?php else: ?>
     <div class="item-<?php echo $i+1 ?>"></div>
<?php endif; ?> 
<?php $i++ ?>
<?php endforeach; ?>
0
0
<?php $i = 0; foreach ($_productCollection as $_product): ?>
    <?php if ($i % 3 == 0): ?>
        <div class="new-to-added-div"></div>
    <?php else: ?>
        <div class="item-<?php echo $i; ?>"></div>
    <?php endif;?>
    <?php $i++; ?>
<?php endforeach; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.