Magento – How to exclude inactive categories from catergories sitemap

categoryPHP

I've just noticed while testing that my sitemap shows inactive categories in on my Magento ver. 1.9.1.0 install. I saw a post that seems to address the issues via the app/design/frontend/base/default/template/catalog/seo/tree.phtml link. My problem is I get a n error code when I try this.

    <?php $_items = $this->getCollection(); ?>
<?php if($_items->getSize()): ?>
    <ul class="sitemap">
    <?php if( $_item->is_active ) : ?> 
        <?php foreach ($_items as $_item): ?>
            <li class="level-<?php echo $this->getLevel($_item) ?>" <?php echo $this->getLevel($_item)?'style="padding-left:' . $this->getLevel($_item, 2) . '0px;"':'' ?>><a href="<?php echo $this->getItemUrl($_item) ?>"><?php echo $_item->name ?></a></li>
        <?php endif; ?> 
        <?php endforeach; ?>
    </ul>
<?php else: ?>
    <p class="note-msg">
        <?php echo $this->__('There are no %s available.', $this->getItemsTitle()); ?>
    </p>
<?php endif ?>

I think because the if statement is not being closed properly. When I trying joining the if statements like this.

<?php $_items = $this->getCollection(); ?>
<?php if($_items->getSize && is_active()): ?>
    <ul class="sitemap">
    <?php foreach ($_items as $_item): ?>
            <li class="level-<?php echo $this->getLevel($_item) ?>" <?php echo $this->getLevel($_item)?'style="padding-left:' . $this->getLevel($_item, 2) . '0px;"':'' ?>><a href="<?php echo $this->getItemUrl($_item) ?>"><?php echo $_item->name ?></a></li>
           <?php endforeach; ?>
    </ul>
     <?php else: ?>
    <p class="note-msg">
        <?php echo $this->__('There are no %s available.', $this->getItemsTitle()); ?>
    </p>

I don't get an error but all that shows is the php else message "There are no available." any help would be appreciated.

Best Answer

Dutch,Please goto class Mage_Catalog_Block_Seo_Sitemap_Tree_Category and here i have see that category collection is filter by active . Default code is right.You may need reindex.

Please out an condition at...

<?php foreach ($_items as $_item): ?>
            <li class="level-<?php echo $this->getLevel($_item) ?>" <?php echo $this->getLevel($_item)?'style="padding-left:' . $this->getLevel($_item, 2) . '0px;"':'' ?>><a href="<?php echo $this->getItemUrl($_item) ?>"><?php echo $_item->name ?></a></li>
           <?php endforeach; ?>
    </ul>

Change the above code to

   <?php
    if(get_class($this)=='Mage_Catalog_Block_Seo_Sitemap_Tree_Category'): ?>
    <?php foreach ($_items as $_item): ?>
        <?php if($_item->getActive()==1) ?>
                <li class="level-<?php echo $this->getLevel($_item) ?>" <?php echo $this->getLevel($_item)?'style="padding-left:' . $this->getLevel($_item, 2) . '0px;"':'' ?>><a href="<?php echo $this->getItemUrl($_item) ?>"><?php echo $_item->name ?></a></li>
             <?php endif ;?>  
           <?php endforeach; ?>
    <?php 
    else: ?>

    <?php foreach ($_items as $_item): ?>
                <li class="level-<?php echo $this->getLevel($_item) ?>" <?php echo $this->getLevel($_item)?'style="padding-left:' . $this->getLevel($_item, 2) . '0px;"':'' ?>><a href="<?php echo $this->getItemUrl($_item) ?>"><?php echo $_item->name ?></a></li>
               <?php endforeach; ?>
    <?php endif; ?>
Related Topic