Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

display subcategories if there are any
 
Althalos
Jr. Member
 
Total Posts:  19
Joined:  2009-08-19
 

I’m trying to display a list of subcategories if there are subcategories in a category, otherwise I will just display the products as usual. So this is the code I got:

<?php if (!Mage::registry('current_category')) return ""; ?>
<?php $_categories=$this->getCurrentChildCategories(); ?>
<?php $_count = is_array($_categories)?count($_categories):$_categories->count(); ?>
<?php if($_count): ?>
display sub categories here
<?php else: ?>
display products here
<?php endif; ?>

But I get this error: Fatal error: Call to a member function count() on a non-object

Can anybody help?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Althalos
Jr. Member
 
Total Posts:  19
Joined:  2009-08-19
 

<?php $_categories = Mage::registry('current_category')->getChildren(); ?>
<?php $_count = is_array($_categories)?count($_categories):$_categories->count(); ?>

gives the same error:
Fatal error: Call to a member function count() on a non-object

Can it depend on which file I call it from? I’m using a file call list.phtml which is located under mytemplate/template/catalog/product/ ...

 
Magento Community Magento Community
Magento Community
Magento Community
 
Althalos
Jr. Member
 
Total Posts:  19
Joined:  2009-08-19
 

Thanks, it works beautifully! smile

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top