2012-09-21 64 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