Magento – Exclude CMS page while creating sitemap.xml in magento admin

cms-pagesmagento-1.9sitemaps

We have certain CMS pages in our magento e-commerce store. Now we need to create sitemap.xml and as we all know magento admin provides to create a sitemap.

But here, the problem is when I generate a sitemap, all the active pages are getting included. We don't want some certain CMS pages in sitemap.

So, how to exclude those page ? Please help.

Best Answer

In this case,

  • You need to create a installer which will create new field (is_used_for_Sitemap)at cms_page table at database.

  • Also its view at Admin cms page view should be dropdown. The rewrite a resource model class Mage_Sitemap_Model_Resource_Cms_Page.

    [ModuleNameSpace]_[ModuleName]_Model_Resource_Cms_Pag

  • and - that function getCollection() add this field as condition (is_used_for_sitemap=1)

Rewrite class should be:

<?php
class [ModuleNameSpace]_[ModuleName]_Model_Resource_Cms_Page 
extends Mage_Sitemap_Model_Resource_Cms_Page
 public function getCollection($storeId)
    {
        $pages = array();

        $select = $this->_getWriteAdapter()->select()
            ->from(array('main_table' => $this->getMainTable()), array($this->getIdFieldName(), 'identifier AS url'))
            ->join(
                array('store_table' => $this->getTable('cms/page_store')),
                'main_table.page_id=store_table.page_id',
                array()
            )
            ->where('main_table.is_active=1')
            ->where('main_table.is_used_for_sitemap=1') // code
            ->where('store_table.store_id IN(?)', array(0, $storeId));
        $query = $this->_getWriteAdapter()->query($select);
        while ($row = $query->fetch()) {
            if ($row['url'] == Mage_Cms_Model_Page::NOROUTE_PAGE_ID) {
                continue;
            }
            $page = $this->_prepareObject($row);
            $pages[$page->getId()] = $page;
        }

        return $pages;
    }
  } 
Related Topic