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

[resolved] show inactive categories
 
Belmont1
Jr. Member
 
Total Posts:  5
Joined:  2009-03-05
 

Hi, I have a little problem, I created a block to show categories on the homepage, it went well so far because I only had to show the active one. Here’s the code I use :

<?php $helper Mage::helper('catalog/category'); ?>
<?php $categories 
$helper->getStoreCategories(); ?>
<?php 
if(count($categories)): ?>
    
<div>
        
<?php foreach ($categories as $_category): ?>
            <?php $cur_category 
Mage::getModel('catalog/category')->load($_category->getId()); ?>
            <?php $layer 
Mage::getSingleton('catalog/layer'); ?>
            <?php $layer
->setCurrentCategory$cur_category ); ?>
            <?php 
if($_category->getIsActive()): ?>
                
<div class="venteactive">
                <
p><a href="<?php echo $layer->getCurrentCategory()->getUrl(); ?>"><img class="imgventeon" src="<?php echo $layer->getCurrentCategory()->getImageUrl(); ?>" alt="<?php echo $layer->getCurrentCategory()->getName();?>" /></a></p>
                </
div>
            
<?php endif ?>
        <?php 
endforeach ?>
    
</div>
<?php endif ?>

Now the problem is that I want to show under the active categories the inactive one as “sale to come”, and when testing it I could see that $_category->getIsActive() was useless here because even without this it only show the active category. So it seems that $helper->getStoreCategories(); only get the active categories. Is there anyone here who knows how to get the inactive categories as well ?
And by the way, I’m working with magento 1.3.2.1.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Belmont1
Jr. Member
 
Total Posts:  5
Joined:  2009-03-05
 

Thanks for your answer tsyganu, I didn’t even think about collection until know. A whole new magento appears before me XD I’m still having trouble understanding all but I got the main idea.

It helped me, but I changed ‘eq’=>2 by ‘eq’=>3, because the id of my Root Category is 3 and also changed the attribute to select with (’*’) in order to have the url, the name and the source image (otherwise nothing appears), but it still takes only the active categories. I don’t understand why, they seemed to be rattached to the root category, isn’t there something somewhere that prevents to select inactive categories ?.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Belmont1
Jr. Member
 
Total Posts:  5
Joined:  2009-03-05
 

Hmm, I really don’t know where was the “bug”, maybe when trying to rebuild categories or things like that it changed something, don’t know. So for listing the active categories, then the inactive one, here’s the code :

<?php $categories Mage::getModel('catalog/category')->getCollection()
    ->
addAttributeToFilter(array(array('attribute'=>'parent_id''eq'=>3)))//first level from the tree
    
->addAttributeToSelect('*')//or any other attributes you need
    
->setOrder('position');  ?>
<?php 
if(count($categories)): ?>
    
<div>
        
<?php foreach ($categories as $_category): ?>
            <?php $cur_category 
Mage::getModel('catalog/category')->load($_category->getId()); ?>
            <?php $layer 
Mage::getSingleton('catalog/layer'); ?>
            <?php $layer
->setCurrentCategory$cur_category ); ?>
            <?php 
if($_category->getIsActive()): ?>
                
<div class="venteactive">
                <
p><a href="<?php echo $layer->getCurrentCategory()->getUrl(); ?>"><img class="imgventeon" src="<?php echo $layer->getCurrentCategory()->getImageUrl(); ?>" alt="<?php echo $layer->getCurrentCategory()->getName();?>" /></a></p>
                </
div>
            
<?php else: 
                
$inactivecategories[] $_category;
             endif 
?>            
        <?php 
endforeach ?>
        <?php 
foreach ($inactivecategories as $_category): ?>
            <?php $cur_category 
Mage::getModel('catalog/category')->load($_category->getId()); ?>
            <?php $layer 
Mage::getSingleton('catalog/layer'); ?>
            <?php $layer
->setCurrentCategory$cur_category ); ?>
                
<div class="venteactive">
                <
p><a href="<?php echo $layer->getCurrentCategory()->getUrl(); ?>"><img class="imgventeon" src="<?php echo $layer->getCurrentCategory()->getImageUrl(); ?>" alt="<?php echo $layer->getCurrentCategory()->getName();?>" /></a></p>
                </
div>           
        
<?php endforeach ?>
    
</div>
<?php endif ?>

So again, thanks for your help, I’m sure collections will greatly help me smile

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