Magento News
PHP/Magento – Variables within foreach not being updated properly
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…
PHP/Magento – Variables within foreach not being updated properly
Possibly Related Posts:
- Database query different results
- Menu highlight in magento under admin
- magento disable a banner on certain category pages or have a banner with multiple links
- Magento, using ACL for frontend. Possible?
- Magento IE-7 Fix In Windows XP
RSS Feed