0

I want to display a list of a related categories ( categories that the product is in ) on every product page , but the content will be specific to each product.

I have written the code to get the related categories , ( i.e. the code below works fine ) but I am unsure how to cache it dynamically by product page.

<?php
$product = Mage::registry('current_product');
$categoryCollection = $product->getCategoryCollection()
->addAttributeToSelect('name')
->addAttributeToSelect('url');
?>
<div class="block block-vertnav hide-below-768">
    <div class="block-title">
        <strong><span>Related Categories</span></strong>
    </div>
    <div class="block-content">
        <ul class="accordion accordion-style1 sideacco">
<?php 
    $count = count($categoryCollection);
    $position = 1;
    foreach ($categoryCollection as $category) {
    $ulClass = "nav-item level0 nav-1";
    if($position==1){
        $ulClass = $ulClass . " first";
    }
    if($position==$count){
        $ulClass = $ulClass . " last";
    }
?>
            <li class="<?php echo $ulClass; ?>"><a href="<?php echo $category->getUrl(); ?>"><span><?php echo $category->getName(); ?> (<?php echo $category->getProductCount(); ?>)</span></a></li>
<?php
    $position++;
} ?>
        </ul>
    </div>
</div>

Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.