Magento Sitemap Displaying Inactive and Empty Categories

For some reason Magento displays a category in the human readable sitemap even if the category is empty or set inactive. I am currently at CE 1.7.1 and the sitemap still displays inactive and empty categories.

To be sure, this is the URL of the sitemap type I am referring to:

http://www.yourdomain.com/catalog/seo_sitemap/category/

There is a very dated Magento Forum post addressing the issue at

The solution then and today is to edit the template Magento template file that displays the category sitemap.

So, what you can do is copy/create the core sitemap template file to your
own interface/theme. For me it looked something like this:

mkdir mimi_interface/default/template/catalog/seo
cp base/default/template/catalog/seo/tree.phtml mimi_interface/default/template/catalog/seo

You can now edit your file. Comment #3 from the Magento Forum post made
March 22, 2010 still works today. You can find it here:

Basically, the fix calls for adding a simple if statement in the foreach loop. This checks if a category is active before printing it in the Magento category sitemap.

Here is the code change made to the tree.phtml file:

Existing code in tree.phtml:

    <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>

Change by adding an if statement within the foreach:

    <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>

This should take care of the issue with the Magento Sitemap displaying inactive categories.

Post written by Ed Reckers

Founder and lead web development consultant at Red Bridge Internet : San Francisco WordPress Developers and Consultants.

Leave a Reply