主页上的分类图像

时间:2012-08-23 14:53:07

标签: php magento

我正在使用下面的代码,该代码将我的所有SUB类别从我的主要产品类别提取到主页。

我需要以某种方式能够在getName函数下提取子类别的类别图像。我尝试了之前提到的一些方法,但没有一种方法有效。

如果有帮助,我使用1.7.0。

<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::registry('current_category') ?>
<?php if (count($_categories) > 0): ?>
<ul>
    <?php foreach($_categories as $_category): ?>
        <li> 
            <?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 class="item">
                            <a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
                                <?php echo $_subcategory->getName() ?>

                            </a>
                        </li>
                    <?php endforeach; ?>
                </ul>
            <?php endif; ?>
        </li>
    <?php endforeach; ?>
</ul>
<?php endif; ?>

2 个答案:

答案 0 :(得分:0)

通过将代码更改为

来管理实现它
<?php
//gets all sub categories of parent category 'Brands'
$cats = Mage::getModel('catalog/category')->load(27)->getChildren();
$catIds = explode(',',$cats);

$categories = array();
foreach($catIds as $catId) {
    $category = Mage::getModel('catalog/category')->load($catId); 
    $categories[$category->getName()] = array(
        'url' => $category->getUrl(),
        'img' => $category->getImageUrl()
    );
}

ksort($categories, SORT_STRING);
?>
<?php foreach($categories as $name => $data): ?>
        <li class="item">
            <a href="<?php echo $data['url']; ?>" title="<?php echo $name; ?>">
            <div style="font:12px/15px Arial,Helvetica,sans-serif; margin-bottom:10px;"><?php echo $name; ?></div>
                <img class="cat-image" src="<?php echo $data['img']; ?>" />
            </a>
        </li>   
    <?php endforeach; ?>

答案 1 :(得分:0)

你需要在getName函数下编写类似的东西

<img src="<?php echo $_subcategory->getImageUrl()">