Magento – How to exclude inactive categories/pages from generated google sitemap.xml

categorymagento-1.7sitemapsxml

Through Catalog > Google sitemap I have just generated a sitemap.xml file.

The file itself works perfect.
My problem though is, that the file also contains inactive categories.

I can't seem to find any options to exclude these inactive categories from my generated sitemap.xml file.

Do anyone know how this can be solved?

I am using Magento ver. 1.7.0.2

Best Answer

Try this.

Edit the app/design/frontend/your_package/your_theme/template/catalog/seo/tree.phtml file in your theme. Add an if condition just after the foreach loop which checks for activeness of the $_item.

<?php $_items = $this->getCollection(); ?>
<?php if($_items->getSize()): ?>
    <ul class="sitemap">
        <?php foreach ($_items as $_item): ?>
          <?php if( $_item->is_active ) : ?> 
            <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 ?>