如何在magento中获取子类别子图像?

时间:2013-10-23 06:13:20

标签: magento

我没有从儿童类别获得所有图片,请帮助我。

的Pankaj

<table id="t2">
    <tr>
    <?php foreach ($this->getCurrentCategory()->getChildrenCategories() as $_subcat): ?>
    <td>
        <div class="product_2">
            <?php if($_imgUrl): ?>
            <div class="product_img2"><a href="<?php echo $_subcat->getUrl() ?>"><img src="<?php echo $_category->getImageUrl() ?>"  alt="<?php echo Mage::helper('catalog/output')->categoryAttribute($_subcat, $_subcat->getName(), 'name') ?>" /></a></div><p class="text-1"><a href="<?php echo $_subcat->getUrl() ?>"><?php echo Mage::helper('catalog/output')->categoryAttribute($_subcat, $_subcat->getName(), 'name') ?></a></p>
                </div>
    </td>
        <?php endif; ?>
    <?php endforeach ?>
    </tr>
</table>

3 个答案:

答案 0 :(得分:1)

你也可以尝试一下。

$_subcat->getThumbnailImageUrl()

答案 1 :(得分:1)

你可以如下

<?php
    //gets all sub categories of parent category
    $cats = Mage::getModel('catalog/category')->load(your category id)->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); // for sorting purpose 

&GT;

<ul>
    <?php foreach($categories as $name => $data): ?>
        <li>
            <a href="<?php echo $data['url']; ?>" title="<?php echo $name; ?>">
                <img class="cat-image" src="<?php echo $data['img']; ?>" />
            </a>
        </li>   
    <?php endforeach; ?>
</ul>

希望这对您有用,

答案 2 :(得分:0)

更新的代码:

<table id="t2">
<tr>
<?php foreach ($this->getCurrentCategory()->getChildrenCategories() as $_subcat): ?>
<td>
    <div class="product_2">
        <?php // if($_imgUrl):  remove condition?>
        <div class="product_img2">
            <a href="<?php echo $_subcat->getUrl() ?>">
                <!-- Updated below line code, use $_subcat in stead of $_category -->
                <img src="<?php echo $_subcat->getImageUrl(); ?>"  alt="<?php echo Mage::helper('catalog/output')->categoryAttribute($_subcat, $_subcat->getName(), 'name') ?>" /></a>
        </div>
        <p class="text-1">
            <a href="<?php echo $_subcat->getUrl() ?>"><?php echo Mage::helper('catalog/output')->categoryAttribute($_subcat, $_subcat->getName(), 'name') ?></a>
        </p>
    </div>
</td>
<?php // endif; remove condition?>  
<?php endforeach ?>
</tr>

希望会奏效!