【问题标题】:Custom Magento Meta Title自定义 Magento 元标题
【发布时间】:2015-02-21 22:01:55
【问题描述】:

我使用的是 magento 1.9。在产品页面上,元标题就像

“产品名称类别子类别”

我只想显示“PRODUCTNAME - Mysite.com”

如何仅在产品页面上进行此修复?

谢谢。

【问题讨论】:

    标签: magento title meta product


    【解决方案1】:

    Magento 在两个不同的地方设置标题标签。首先在Mage_Catalog_Block_Breadcrumbs里面的_prepareLayout()方法

        $title = array();
        $path  = Mage::helper('catalog')->getBreadcrumbPath();
    
        foreach ($path as $name => $breadcrumb) {
            $breadcrumbsBlock->addCrumb($name, $breadcrumb);
            $title[] = $breadcrumb['label'];
        }
    
        if ($headBlock = $this->getLayout()->getBlock('head')) {
            $headBlock->setTitle(join($this->getTitleSeparator(), array_reverse($title)));
        }
    

    $path 变量的内容会根据您进入产品页面的方式而有所不同。例如:

    直接链接到产品:

    • 网址:/aviator-sunglasses.html
    • title: 飞行员太阳镜

    使用类别菜单导航到产品:

    • 网址:/accessories/eyewear/aviator-sunglasses.html
    • title: 飞行员太阳镜 - 眼镜 - 配饰

    然后在Mage_Catalog_Block_Product_View里面的_prepareLayout()方法

        $product = $this->getProduct();
        $title = $product->getMetaTitle();
        if ($title) {
            $headBlock->setTitle($title);
        }
    

    这里它只是检查是否设置了元标题产品属性,如果是,则覆盖先前设置的标题。所以,你有两个选择:

    1. 为每个产品设置元标题
    2. 重写 Mage_Catalog_Block_Breadcrumbs 类中的 _prepareLayout() 方法

      if ($headBlock = $this->getLayout()->getBlock('head')) {
          if ($product = Mage::registry('current_product')) {
              $storeName = Mage::getStoreConfig('general/store_information/name');
              $pageTitle = $storeName ? $product->getName() . ' - ' . $storeName : $product->getName();
              $headBlock->setTitle($pageTitle);
          } else {
              $headBlock->setTitle(join($this->getTitleSeparator(), array_reverse($title)));
          }
      }
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多