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.

$product = Mage::registry('current_product');
$categoryCollection = $product->getCategoryCollection()
<div class="block block-vertnav hide-below-768">
    <div class="block-title">
        <strong><span>Related Categories</span></strong>
    <div class="block-content">
        <ul class="accordion accordion-style1 sideacco">
    $count = count($categoryCollection);
    $position = 1;
    foreach ($categoryCollection as $category) {
    $ulClass = "nav-item level0 nav-1";
        $ulClass = $ulClass . " first";
        $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>
} ?>


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.