我想将 2 个自定义属性添加到产品页面上的
标签中.它们是品牌"和字幕".
I have 2 custom attributes I'd like to add to the <title>
tags on product pages. They are 'brand' and 'subtitle'.
我的页面标题最终会是这样的:
My page title would end up something like this:
$brand." ".$productname." ".$subtitle;
$brand." ".$productname." ".$subtitle;
我怎样才能做到这一点?
How can I achieve this?
非常感谢您的帮助.
根据您的问题,我假设您指的是更改产品的元标题.
From your question, I assume you are referring to changing the meta title for products.
有 3 个选项可供您选择:
There are 3 options open to you:
您的决定实际上是在选项 2 和选项 2 之间3(这两者都需要你创建一个自定义模块来实现).
Your decision is really between options 2 & 3 (both of which will require you to create a custom module to achieve).
在扩展 Magento 核心功能时,我总是尽量不引人注目 - 所以我会在这里选择选项 3.请参阅以下代码以获取完整示例:
I always try to be as unobtrusive as possible when extending Magento core functionality - so I would opt for option 3 here. Please see below code for a complete example:
app/etc/modules/Yourcompany_Yourmodule.xml
app/etc/modules/Yourcompany_Yourmodule.xml
<?xml version="1.0"?>
<config>
<modules>
<Yourcompany_Yourmodule>
<active>true</active>
<codePool>local</codePool>
</Yourcompany_Yourmodule>
</modules>
</config>
app/code/local/Yourcompany/Yourmodule/etc/config.xml
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>
<yourmodule>
<class>Yourcompany_Yourmodule_Model</class>
</yourmodule>
</models>
</global>
<frontend>
<events>
<catalog_controller_product_view>
<observers>
<yourmodule>
<class>Yourcompany_Yourmodule_Model_Observer</class>
<method>catalog_controller_product_view</method>
</yourmodule>
</observers>
</catalog_controller_product_view>
</events>
</frontend>
</config>
app/code/local/Yourcompany/Yourmodule/Model/Observer.php
app/code/local/Yourcompany/Yourmodule/Model/Observer.php
<?php
class Yourcompany_Yourmodule_Model_Observer
{
/**
* Change product meta title on product view
*
* @pram Varien_Event_Observer $observer
* @return Yourcompany_Yourmodule_Model_Observer
*/
public function catalog_controller_product_view(Varien_Event_Observer $observer)
{
if ($product = $observer->getEvent()->getProduct()) {
$title = $product->getData('brand') . ' ' . $product->getData('name') . ' ' . $product->getData('sub_title');
$product->setMetaTitle($title);
}
return $this;
}
}
这篇关于Magento 更改产品页面标题以包含属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!