从sitemap.xml生成中排除特定页面 [英] Exclude specific page from sitemap.xml generation

查看:101
本文介绍了从sitemap.xml生成中排除特定页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种方法可以排除一个特定的CMS页面,使其不被添加或包含在Magento的站点地图中.

I was wondering if there is a method to exclude one specific CMS page from being added / included in the sitemap generation of Magento.

一些专家的建议将不胜感激.

Some expert advise would be greatly appreciated.

推荐答案

例如,通过像这样覆盖Mage_Sitemap_Model_Resource_Cms_Page::getCollection:

For example by overriding Mage_Sitemap_Model_Resource_Cms_Page::getCollection like this:

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的文章

In case you don't know how to override a Magento model class yet, have a look at Alan Storm's article Magento for Developers: Part 1 - Introduction to Magento, especially sections "Models" and "Class overrides".

这篇关于从sitemap.xml生成中排除特定页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆