I am trying to modify the way a category list is drawn on the front end of a Magento website (simple idea). I have a list of categories that I want to seperate and use with jquery accordiation, so for EG. I want a header “2010 and older” under which sit categories with IDs 1 to 10. Then I want a heading “2011” under which live categories with IDs 11 to 20.
The default category code below just loops through the IDs and echos out the category list in a <UL> – but I want to customise the <UL>:
<?php $collection = $this->_getCollection(); ?>
<?php if (count($collection) > 0) : ?>
<?php foreach ($collection as $_category ) : ?>
<li>
<a href="<?php echo $this->getUrl('gallery/category/view/', array('id' => $_category->getId())); ?>"><?php echo $this->htmlEscape($_category->getName()) ?></a>
</li>
<?php endforeach ?>
<?php endif; ?>
I can’t see the wood for the trees! – I figured to pull the IDs into an array and draw the new structure based on IF statements, but no luck in building the array.
Can anyone see a quick way that I can break the loop to say, if IDs are 1 to 10 then list in <li class="2010">, then move on for IDs 11 to 20 in <li class="2011"> for eg.?
Many Thanks
Try to check for category id’s you don’t want to display and use
continue;to get the next: