Magento在类别list.phtml上显示子类别描述 [英] Magento displays subcategories description on category list.phtml

查看:81
本文介绍了Magento在类别list.phtml上显示子类别描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Magento 中得到了一个带有子类别列表的类别页面.列表中有图像和名称,但我也想显示这些子类别的描述.我只是尝试添加

I got a category page with list of subcategories in Magento. The list has an image and name, but I also want to display those subcategories' description. I tried simply to add

<strong><?php echo $this->htmlEscape($_category->getDescription()) ?></strong>

但是它不起作用.

我以传统方式获得子类别:

I get subcategories in a traditional way:

<?php if (!$_categoryCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no subcategories matching the selection.') ?></p>
<?php else: ?>
<div class="category-products">
    <?php $_collectionSize = $_categoryCollection->count() ?>
    <?php $_columnCount = $this->getColumnCount(); ?>
    <?php $i=0; foreach ($_categoryCollection as $_category): ?>
        <?php if ($i++%$_columnCount==0): ?>
        <ul class="products-grid">
        <?php endif ?>
            <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
                <a href="<?php echo $_category->getUrl() ?>" class="product-image"><img class="photo" src="<?php echo $this->getCategoryImage($_category, 214, 184); ?>" width="214" height="184" alt="<?php echo $_category->getName() ?>" />
                <strong><?php echo $this->htmlEscape($_category->getName()) ?></strong>
                <strong><?php echo $_category->getDescription() ?></strong>
                </a>
            </li>
        <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
        </ul>
        <?php endif ?>
    <?php endforeach ?>
</div>

我试图通过添加->addAttributeToSelect(’description’)来更新category.php文件中的公共功能getChildrenCategories($category),但是它不起作用.

I've tried to update the public function getChildrenCategories($category) in the category.php file by adding ->addAttributeToSelect(’description’), but it's not working.

推荐答案

我看不到您做错了什么,但也许我仍然可以提供帮助.我已经在list.phtml中成功显示了子类别的描述,您也许可以将对我有用的内容适应您的目的.以下是对我有用的代码的简化版本:

I can't see what exactly it is that you're doing wrong, but perhaps I can still help. I have successfully displayed the child category descriptions in list.phtml and you may be able to adapt what's working for me to your own purposes. The following is a stripped-down version of the code which works for me:

<?php $children = explode( ",", $this->getCurrentCategory()->getChildren() ); ?>
<div class="category-products">
    <ul class="products-grid">
        <?php foreach( $children as $child ): ?>
            <?php $_child = Mage::getModel( 'catalog/category' )->load( $child ); ?>
            <li class="item"><?php echo $_child->getDescription(); ?></li>
        <?php endforeach; ?>
    </ul>
</div>

您正在做的工作与上面的示例之间的最大区别是,目录模型对象上的getChildren()方法返回了一个类别ID数组,然后我使用类别ID加载了相应的子类别模型实例.我的记忆可能在这里是错误的,但我似乎还记得从Magento集合返回的项目不包含按ID加载时获得的全部数据.

The big difference between what you're doing and my sample above is that the getChildren() method on the catalog model object returns an array of category Ids and I then use the category Ids to load the corresponding child category model instances. My memory may be wrong here, but I seem to remember that the items returned from a Magento collection don't contain the full data that you get when you load by id.

我不确定这是否会显着影响性能(我认为加载集合比加载单个模型要快),但是它可以正常工作,所以我不会抱怨...

I'm not sure if this will affect performance significantly or not (I would assume that loading a collection is faster than loading individual models) but it works so I'm not complaining...

希望这会有所帮助.

干杯, 扎克

这篇关于Magento在类别list.phtml上显示子类别描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆