0

我需要列出所有类别和相应的缩略图。问题是我无法显示缩略图。我已经尝试了所有教程,但什么也没有。这是解释不同方法的帖子列表,但没有一种方法有效:我无法使它们起作用的示例列表

这是我当前的代码:

<?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; ?>
4

1 回答 1

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; ?>
于 2013-05-14T22:18:59.087 回答