0

我正在使用下面的代码,它将我的所有子类别从我的主要产品类别拉到主页上。

我需要能够以某种方式在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; ?>
4

2 回答 2

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; ?>
于 2012-08-23T15:40:30.350 回答
0

你需要在 getName 函数下写这样的东西

<img src="<?php echo $_subcategory->getImageUrl()">
于 2012-08-23T15:46:09.697 回答