2012-09-21 67 views
3

我想知道是否有一种方法可以排除一个特定的CMS页面被添加/包含在Magento的站点地图生成中。从sitemap.xml生成排除特定页面

一些专家建议将不胜感激。通过重写Mage_Sitemap_Model_Resource_Cms_Page::getCollection这样

回答

3

例如:

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" 
     ->where('main_table.identifier<>"enable-cookies"') 
     // --- exclude multiple CMS pages "home", "enable-cookies" 
     // ->where('main_table.identifier NOT IN (?)', array('home', '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; 
} 

如果你不知道如何重写Magento的模型类呢,看看艾伦风暴的文章Magento for Developers: Part 1 - Introduction to Magento,尤其是部分“型号”和“类覆盖”。

+0

谢谢你领导Thelen先生。这似乎是一个相当复杂的解决方案。如果我想排除我的主要主页被包含在网站地图生成中,我该如何应用此功能。这个名字本身就是“家”。您的专家建议将会被大大地抹杀。 – TheDave

+0

好吧,在上面的例子中,我排除了CMS页面“enable-cookies”作为例子,所以你只需要用'“home”'替换''enable-cookies'''。 –

+0

非常感谢Thelen先生! – TheDave