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

Add Subcategories to list.phtml
 
focusnet
Jr. Member
 
Total Posts:  5
Joined:  2008-06-13
 

Hello,

I have tried to add all Subcategories of a maincategory to display in list.phtml. There are some examples in this forum like:

<?php 
/* Check the category variable loop against the current category path if it is - print sub categories */
if (in_array($this->getCurrentCategory()->getId(), $_categorypath)): ?>
<?php $_maincategorylisting
=$this->getCurrentCategory()?>                        
<?php $_categories
=$this->getCurrentChildCategories()?>
<?php 
if($_categories->count()):?>

<ul>
<? foreach ($_categories as $_category):?>                    
   <? 
if($_category->getIsActive()):                    
           
$cur_subcategory=Mage::getModel('catalog/category')->load($_category->getId());
           
$layer Mage::getSingleton('catalog/layer');
           
$layer->setCurrentCategory($cur_subcategory);  
          
?>                          
<li><a href="<?php echo $this->getCategoryUrl($_category)?>"<?php echo $_category->getName()?></a></li>
    
<? endif;?>
<? 
endforeach ?>
</ul>            
<?php /* This resets the category back to the original pages category
****     If this is not done, subsequent calls on the same page will use the last category
****    in the foreach loop
*/   
?>
<?php $layer
->setCurrentCategory($_maincategorylisting);  ?> 
<? 
endif; ?>   
 
<? 
endif; ?>

I have also tried to add a part of the Navigation - Script to the list.phtml. But there is the same error:
Fatal error: Call to a member function getId() on a non-object

It seems there is a problem to fetch the current category and the subcategories.

Thank you for any help.

Greets from Switzerland…

 
Magento Community Magento Community
Magento Community
Magento Community
 
tobillo
Member
 
Avatar
Total Posts:  46
Joined:  2008-04-07
Germany
 

hi,

i have a similar problem. I need the subcategorie of a product in many pages like the cart, the invoice, the advanced search. Has anybody an idea or function to get the category/subcategory of a product in this pages?

Best!

Oliver

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