我想知道是否有一种方法可以排除某个特定的CMS页面被添加/包含在Magento的站点地图生成中。
非常感谢一些专家的建议。
答案 0 :(得分:4)
例如,通过覆盖Mage_Sitemap_Model_Resource_Cms_Page::getCollection
这样:
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模型类,请查看Alan Storm的文章Magento for Developers: Part 1 - Introduction to Magento,特别是“模型”和“类重写”部分。