I am using magento 1.7. I create a category "A" and in it i create others categories. I created a static block and affect to the category "A". I wish to display the categories name and his count in all categories using static block. Can i do that with static block or with other solution ?
1 Answer
You sure can - first, create a custom block:
YourCompany_YourModule_Block_Category extends Mage_Core_Block_Abstract
{
protected function _toHtml()
{
$category = Mage::registry('current_category');
$name = $category->getName();
$numProducts = $category->getCollection()->getSize();
$html = parent::_toHtml();
return $html .= "$name, number of products: $numProducts";
}
}
Then you add it to your static block:
{{block type='yourblock/category' name='your.custom.name'}}
If all goes well, you should see at the top of your category something like "Televisions, number of products: 42".
Best of luck!