Magento:Canonical Link消失了

时间:2016-01-05 16:03:47

标签: magento canonical-link

我修改了Mage_Catalog_Block_Category_View类中的_prepareLayout()函数,以获得自定义的规范网址。修改URL后,规范代码不再显示在html源代码中。

以下是我的代码:

    protected function _prepareLayout() {

    Mage_Core_Block_Template::_prepareLayout();

    $this->getLayout()->createBlock('catalog/breadcrumbs');

    if ($headBlock = $this->getLayout()->getBlock('head')) {
        $category = $this->getCurrentCategory();
        if ($title = $category->getMetaTitle()) {
            $headBlock->setTitle($title);
        }
        if ($description = $category->getMetaDescription()) {
            $headBlock->setDescription($description);
        }
        if ($keywords = $category->getMetaKeywords()) {
            $headBlock->setKeywords($keywords);
        }
        if ($this->helper('catalog/category')->canUseCanonicalTag()) {
            //$headBlock->addLinkRel('canonical', $category->getUrl());
            if ($category->getCategoryUrlAlias()) {
                $url = Mage::getBaseUrl() . $category->getCategoryUrlAlias();
            } else {
                $key = $this->helper('my_package/category')->getIsTitleCategoryKey($category);
                $url = $category->getUrl();
                $url = $this->_removeKeyFromUrl($url, $key);
            }
            $headBlock->addLinkRel('canonical', $url);
        }
        /*
          want to show rss feed in the url
         */
        if ($this->IsRssCatalogEnable() && $this->IsTopCategory()) {
            $title = $this->helper('rss')->__('%s RSS Feed', $this->getCurrentCategory()->getName());
            $headBlock->addItem('rss', $this->getRssLink(), 'title="' . $title . '"');
        }
    }

    return $this;
}

我已经验证$ url变量始终具有我想要的自定义url值。我想知道是否有任何验证功能阻止我有自定义的规范URL?

任何帮助将不胜感激。谢谢!

0 个答案:

没有答案