Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
动态获取magento元关键字?_Magento_Seo_Meta - Fatal编程技术网

动态获取magento元关键字?

动态获取magento元关键字?,magento,seo,meta,Magento,Seo,Meta,在magento的产品页面上,我想在meta keywords标签中获取产品名称、其类别名称和子类别名称 请帮忙 提前谢谢。您是指产品详细信息页面吗?如果是,表示非常简单 转到您的特定产品页面,应该有选项卡“元信息”。您可以在这里添加 Meta Title, Meta Keywords, Meta Description 您是指产品详细信息页面吗?如果是,表示非常简单 转到您的特定产品页面,应该有选项卡“元信息”。您可以在这里添加 Meta Title, Meta Keywords, Meta

在magento的产品页面上,我想在meta keywords标签中获取产品名称、其类别名称和子类别名称

请帮忙


提前谢谢。

您是指产品详细信息页面吗?如果是,表示非常简单

转到您的特定产品页面,应该有选项卡“元信息”。您可以在这里添加

Meta Title, Meta Keywords, Meta Description

您是指产品详细信息页面吗?如果是,表示非常简单

转到您的特定产品页面,应该有选项卡“元信息”。您可以在这里添加

Meta Title, Meta Keywords, Meta Description

您必须重写Mage_Catalog_Block_Product_View类,尤其是u preparelayout()方法

只需在将覆盖的_prepareLayout方法中添加以下代码:

protected function _prepareLayout()
{
    $currentCategory = Mage::registry('current_category'); // For accessing current category information
    $product = $this->getProduct();

    if ($headBlock = $this->getLayout()->getBlock('head')) {
      $headBlock->setTitle("Whatever you want here");   
      $product->setMetaKeyword("whatever, keywords, you, want, here");   
      $product->setMetaDescription("Whatever description you want here);   
    }

    return parent::_prepareLayout();
}
按照上面描述的方式设置metakeyword和metadescription非常重要,否则父类将再次覆盖它

问候,,
Kenny

您必须重写Mage\u Catalog\u Block\u Product\u View类,尤其是u preparelayout()方法

只需在将覆盖的_prepareLayout方法中添加以下代码:

protected function _prepareLayout()
{
    $currentCategory = Mage::registry('current_category'); // For accessing current category information
    $product = $this->getProduct();

    if ($headBlock = $this->getLayout()->getBlock('head')) {
      $headBlock->setTitle("Whatever you want here");   
      $product->setMetaKeyword("whatever, keywords, you, want, here");   
      $product->setMetaDescription("Whatever description you want here);   
    }

    return parent::_prepareLayout();
}
按照上面描述的方式设置metakeyword和metadescription非常重要,否则父类将再次覆盖它

问候,,
Kenny

由于产品已经附加了元关键字值,您可以使用观察者以不引人注目的方式扩展该值。此方法不涉及扩展核心类

试试这个:

/app/code/local/YourCompany/YourModule/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <YourCompany_YourModule>
            <version>1.0.0</version>
        </YourCompany_YourModule>
    </modules>
    <global>
        <models>
            <YourCompany_YourModule>
                <class>YourCompany_YourModule_Model</class>
            </YourCompany_YourModule>
        </models>
    </global>
    <frontend>
        <events>
            <catalog_controller_product_view>
                <observers>
                    <YourCompany_YourModule>
                        <class>YourCompany_YourModule/Observer</class>
                        <method>productView</method>
                    </YourCompany_YourModule>
                </observers>
            </catalog_controller_product_view>
        </events>
    </frontend>
</config>

1.0.0
你的公司(你的模块)模式
您的公司\您的模块/观察员
产品视图
/app/code/local/YourCompany/YourModule/Model/Observer.php

<?php
class YourCompany_YourModule_Model_Observer
{

    public function productView(Varien_Event_Observer $observer)
    {
        $product = $observer->getEvent()->getProduct();
        /* @var $product Mage_Catalog_Model_Product */

        if ($product) {
            $keywords = $product->getMetaKeyword();

            // Add the product name
            $keywords = ' ' . $product->getName();

            // Add the category name
            $currentCategory = Mage::registry('current_category');
            if ($currentCategory && $currentCategory instanceof Mage_Catalog_Model_Category) {
                $keywords = ' ' . $currentCategory->getName();
            }

            $product->setMetaKeyword($keywords);
        }
    }

}

由于产品已经附加了MetaKeyword值,您可以使用观察者以不引人注目的方式扩展该值。此方法不涉及扩展核心类

试试这个:

/app/code/local/YourCompany/YourModule/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <YourCompany_YourModule>
            <version>1.0.0</version>
        </YourCompany_YourModule>
    </modules>
    <global>
        <models>
            <YourCompany_YourModule>
                <class>YourCompany_YourModule_Model</class>
            </YourCompany_YourModule>
        </models>
    </global>
    <frontend>
        <events>
            <catalog_controller_product_view>
                <observers>
                    <YourCompany_YourModule>
                        <class>YourCompany_YourModule/Observer</class>
                        <method>productView</method>
                    </YourCompany_YourModule>
                </observers>
            </catalog_controller_product_view>
        </events>
    </frontend>
</config>

1.0.0
你的公司(你的模块)模式
您的公司\您的模块/观察员
产品视图
/app/code/local/YourCompany/YourModule/Model/Observer.php

<?php
class YourCompany_YourModule_Model_Observer
{

    public function productView(Varien_Event_Observer $observer)
    {
        $product = $observer->getEvent()->getProduct();
        /* @var $product Mage_Catalog_Model_Product */

        if ($product) {
            $keywords = $product->getMetaKeyword();

            // Add the product name
            $keywords = ' ' . $product->getName();

            // Add the category name
            $currentCategory = Mage::registry('current_category');
            if ($currentCategory && $currentCategory instanceof Mage_Catalog_Model_Category) {
                $keywords = ' ' . $currentCategory->getName();
            }

            $product->setMetaKeyword($keywords);
        }
    }

}

我猜他想添加dynamicallyi猜他想添加dynamicallyyi,meta-keywords标签对页面排名没有影响。没有主要的搜索引擎再使用它们了。仅供参考,meta关键字标签对页面排名没有影响。没有主要的搜索引擎再使用它们了。