cancel
Showing results for 
Search instead for 
Did you mean: 

Display subcategories in parent category with category images in 1.9.2

SOLVED

Display subcategories in parent category with category images in 1.9.2

Hello everyone,

 

I was using this great method for 1.7 version, but when 1.9.2 rolled out I can't seem to figure out the image path correctly. Here's the code I am using.

 

<?php
$category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
$categories = $category->getCollection()
->addAttributeToSelect(array('name', 'image'))
->addAttributeToFilter('is_active', 1)
->addAttributeToSort('position')
->addIdFilter($category->getChildren())
?>
<ul class="subcategories">
    <?php foreach ($categories as $category): ?>
        <li>
            <a href="<?php echo $category->getUrl() ?>"><img src="getImageUrl() ?>" />
                <span><?php echo $category->getName() ?></span></a>
        </li>
    <?php endforeach; ?>
</ul> 

Thank you guys in advanced.

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Display subcategories in parent category with category images in 1.9.2

your code is broken try

<a href="<?php echo $category->getUrl() ?>"><img src="<?php echo $category->getImageUrl(); ?>" />

and let me know if it works.

View solution in original post

2 REPLIES 2

Re: Display subcategories in parent category with category images in 1.9.2

your code is broken try

<a href="<?php echo $category->getUrl() ?>"><img src="<?php echo $category->getImageUrl(); ?>" />

and let me know if it works.

Re: Display subcategories in parent category with category images in 1.9.2

That works great for category images!

 

Thank you very much.

 

And my other question is: is it possible to still display thumbnails in this code for 1.9.2? Maybe I need to find a way to change the output size of the category image in this parent category. They're bannered sized.

 

This used to work in 1.7 version for thumbnails:

<?php
$category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
$categories = $category->getCollection()
        ->addAttributeToSelect(array('name', 'thumbnail'))
        ->addAttributeToFilter('is_active', 1)
        ->addIdFilter($category->getChildren())
?>
<ul class="subcategories">
    <?php foreach ($categories as $category): ?>
        <li>
            <a href="<?php echo $category->getUrl() ?>"><img src="<?php echo Mage::getBaseUrl('media') . 'catalog' . DS . 'category' . DS . $category->getThumbnail() ?>" alt="<?php echo $this->htmlEscape($category->getName()) ?>" />
                <span><?php echo $category->getName() ?></span></a>
        </li>
    <?php endforeach; ?>
</ul>