I'm having problems with a foreach loop in a magento template:
$cats = Mage::helper('catalog/category')->getStoreCategories();
foreach ($cats as $cat) {
if($cat->getIsActive()&&$cat->getProductCount()) {
echo "<div class=\"grid_6\">";
echo $this->getLayout()->createBlock('catalog/product_new')
->setTemplate('catalog/product/new.phtml')
->setCategoryId($cat->getId())
->setColumnCount(2)
->setBlockTitle("Just Added in <a href=".$cat->getUrl().">".$cat->getName()."</a>")
->toHtml();
echo "</div>";
}
}
Results in an identical block being repeated 4 times (I have 4 main categories) when it should show 4 different blocks, one for each category. It's as if the $cat->getId(), $cat->getName() and $cat->getUrl() statements are not being updated on each new iteration.
What am I doing wrong here?
Thanks...