在magento head.phtml中回显产品属性

use*_*269 4 magento canonical-link magento-1.7

我试图通过使用自定义属性在Magento中为产品设置我自己的自定义规范链接但我无法在head.phtml文件中获取该属性.这就是我到目前为止所拥有的.请有人帮忙吗?

<?php if (Mage::registry('current_product')) : ?>
<?php $customcanonical = Mage::registry(‘current_product’)->getData(‘canonical_link’); ?>
<link rel="canonical" content="<?php echo $customcanonical ?>" />
<?php endif; ?>
Run Code Online (Sandbox Code Playgroud)

其中canonical_link是我的自定义属性

100*_*les 5

尝试这样的事情:

<?php if ($_product = Mage::registry('current_product')) : ?>
<?php $customcanonical = $_product->getData('canonical_link'); ?>
<?php if ($customcanonical): ?>
<link rel="canonical" content="<?php echo $customcanonical ?>" />
<?php endif; ?>
<?php endif; ?>
Run Code Online (Sandbox Code Playgroud)

还要确保您的'canonical_link'属性位于当前使用的属性集中,并且具有您正在查看的当前产品的指定值.如果此属性或产品是新的(或者如果使用平面目录,请确保重新索引!)最后,如果您有缓存,请确保刷新它以便出现新的更改(或在开发新的时禁用它)站点环境或本地站点的功能.)