1

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.

2 Answers 2

0

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;
    }
  } 
0

Just you have to create your custom module with this code, and rewrite this class. The rewrite a resource model class Mage_Sitemap_Model_Resource_Cms_Page.

<?php
class NameSpace_Modulename_Model_Sitemap_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()
         )
         // --- exclude single CMS page "enable-cookies" 
         // --- exclude multiple CMS pages "home", "enable-cookies"

         ->where('main_table.identifier NOT IN (?)', array('handelsbetingelser', 'enable-cookies')) 

         //->where('main_table.identifier<>"enable-cookies"')
         ->where('main_table.is_active=1')
         ->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;

   }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.