My store running on Magento 1.942.
I want to display subcategories on a category page, and find this guide https://www.magemonkeys.com/how-to-display-sub-categories-on-a-category-page-in-magento/.
I create a Static Blocks and subcategory_listing.phtml according to the guide, everything works fine.
but when I enable cache in "Cache Storage Management", All parent categories on my store display the same subcategories (For example, after refreshing the Magento cache, if I click on the A parent category and then click on the other parent category, the subcategories under the A parent category are displayed.).
I refreshed the Magento cache, the browser cache, but nothing changed.
here are the codes of subcategory_listing.phtml
<?php
$layer = Mage::getSingleton('catalog/layer');
$_category = $layer->getCurrentCategory();
$_categories = $_category->getCollection()->addAttributeToSelect(array('url_key','name','image','all_children','is_anchor','description'))
->addAttributeToFilter('is_active', 1)
->addIdFilter($_category->getChildren())
->setOrder('position', 'ASC')
->joinUrlRewrite();
?>
<div class="listing-type-list catalog-listing">
<ul id="subcats" class="clear">
<?php foreach ($_categories as $_category): ?>
<?php if($_category->getIsActive()): ?>
<?php Mage::log($_category->debug(), null, 'mylogfile.log'); ?>
<li>
<div class="category-box clearfix">
<a class="now-from-container" href="<?php echo $_category->getURL() ?>"></a>
<div class="category-image-box">
<a href="<?php echo $_category->getURL() ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>">
<img src="<?php echo $this->htmlEscape($_category->getImageUrl()) ?>" width="135" alt="<?php echo $this->htmlEscape($_category->getName()) ?>" />
</a>
</div>
<div class="category-name">
<h2><a href="<?php echo $_category->getURL() ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>"><?php echo $this->htmlEscape($_category->getName()) ?></a></h2>
</div>
</div>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
</div>
<div style="clear:both;"> </div>