3

不同类别的页面应该显示不同的页脚,这是背后的想法。我知道有很多类似的问题,我都试过了,但没有奏效。我已将自定义类别属性添加到类别页面,我想在页脚中看到它。

我尝试使用:

<?php if($_customAttribute = $this->getCurrentCategory()->getCustomAttribute()):  ?>

<?php echo $_helper->categoryAttribute($_category, $_customAttribute, 'footer_text') ?> 

但我没有得到任何结果。

4

1 回答 1

1

你可以这样试试。

$category = Mage::registry('current_category');
<?php if ($category->getFooterText()) : ?>
    <?php echo Mage::helper('catalog/output')->categoryAttribute($category, $category->getFooterText(), 'footer_text');?>
<?php endif;?>

但请记住...如果您在 footer.phtml 中添加它,它将无法与块缓存一起使用。页脚被缓存,所以一旦你加载一个页面,上面的代码将不会影响下一页。
[编辑]
如果您想在某些页面上有不同的页脚,您需要修改页脚块的缓存键。这里有一个关于如何做到这一点的解释,它是针对一个简单的页面而不是一个类别。概念是一样的。
您需要做的只是将getCacheKeyInfo方法更改为依赖于类别。像这样的东西:

public function getCacheKeyInfo()
{
    $info = parent::getCacheKeyInfo();
    $category = Mage::registry('current_category');
    if ($category) {
        $info[] = $category->getId();
    }
    return $info;
}
于 2013-08-09T07:46:41.627 回答