6

我想在左侧栏中而不是主列中显示类别描述。

我将此添加到我的 catalog.xml 中:

    <reference name="left">
        <block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/>
    </reference>
            <reference name="left">
        <block type="catalog/navigation" name="catalog.catdes" after="catalog.leftnav" template="catalog/navigation/description.phtml"/>
    </reference>

我创建了这个文件:catalog/navigation/description.phtml

    <?php
$_helper = $this->helper('catalog/output');
$_category = $this->getCurrentCategory();
   ?>
        <?php if($_description=$this->getCurrentCategory()->getDescription()): ?>
<div class="category-description">
    <?php echo $_helper->categoryAttribute($_category, $_description, 'description') ?>
</div>

根本没有结果。我可能做错了什么?

4

4 回答 4

9

以下为我解决了这个问题。

echo Mage::getModel('catalog/layer')->getCurrentCategory()->getDescription(); 
于 2013-12-12T23:11:48.360 回答
4

您是否刚刚尝试回显 $_description,因为您在 if 语句中将其设置为相等?

如果这不起作用,那么只需尝试加载它:

$cat = Mage::getModel('catalog/category')->load($_category->getId());
$description = $cat->getDescription();
于 2013-05-08T06:40:26.863 回答
2
<?php if($category = Mage::registry('current_category')): ?>
<div class="category-description std">
    <?php echo $category->getDescription(); ?>
</div>
<?php endif; ?>
于 2015-05-05T10:25:56.167 回答
0

自定义 phtml 文件中的任何位置:

<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$currentCategory = $objectManager->get('Magento\Framework\Registry')->registry('current_category');//get current category information

echo $currentCategory->getDescription();

?>
于 2020-12-15T08:57:53.067 回答