Magento 1.7所有类别和相应的缩略图

时间:2013-05-14 21:42:19

标签: magento-1.7 thumbnails categories

我需要列出所有类别和相应的缩略图。问题是我无法显示缩略图。我已经尝试了所有教程而没有。以下是解释不同方法的帖子列表,但其中一个方法有效: List of examples that I cant make them work

这是我目前的代码:

<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>

<?php if (count($_categories) > 0): ?>
    <ul>
        <?php foreach($_categories as $_category): ?>
            <li>
                <a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
                    <?php echo $_category->getName() ?>
                </a>
                <?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
                <?php $_subcategories = $_category->getChildrenCategories() ?>
                <?php if (count($_subcategories) > 0): ?>
                    <ul>
                        <?php foreach($_subcategories as $_subcategory): ?>
                            <li>
                                <a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
                                    <?php echo $_subcategory->getName() ?>
                                </a>
                            </li>
                        <?php endforeach; ?>
                    </ul>
                <?php endif; ?>
            </li>
        <?php endforeach; ?>
    </ul>
<?php endif; ?>

1 个答案:

答案 0 :(得分:1)

知道了。结果如下,我们需要集合的属性,然后从相应的文件夹中获取图像:

<?php $_helper = Mage::helper('catalog/category'); ?>
<?php $_categories = $_helper->getStoreCategories(false, true, false)
                    //Here is the solution
                    ->addAttributeToSelect('thumbnail')                    
                    ->addOrderField('name');
 ?>
<?php if (count($_categories) > 0): ?>
    <ul>
        <?php foreach($_categories as $_category): ?>
            <li>
                <a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
                    <?php 
                        echo $_category->getName();
                        echo '<img src="'.Mage::getBaseUrl('media').'catalog/category/'.$_category->getThumbnail().'" width="100" height="100"/>';
                    ?>
                </a>
            </li>
        <?php endforeach; ?>
    </ul>
<?php endif; ?>