Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Simplest Call to Get Category Image URL
 
zigojacko
Jr. Member
 
Total Posts:  13
Joined:  2010-09-05
 

I’m displaying a list of sub categories by parent category ID and am wanting to display the category image in place of a category name.

Here is what I have so far…

<div id="menu_brands">
<
div class="brand_head">
    <
h3><?php echo $this->__('Browse By Brand'?></h3>
</
div>
<
div class="brand_list">
    
<?php
        $cats 
Mage::getModel('catalog/category')->load(6)->getChildren();
        
$catIds explode(',',$cats);

        
$categories = array();
            foreach(
$catIds as $catId{
                $category 
Mage::getModel('catalog/category')->load($catId); 
                
$categories[$category->getName()$category->getUrl();
                
$img $category->getImageUrl(); //I suspect this line is wrong
        
}

        ksort
($categoriesSORT_STRING);
    
?>

        
<ul>
            
<?php foreach($categories as $name => $url): ?>
                
<li>
                    <!--<
a href="<?php echo $url; ?>"><?php echo $name?></a>-->
                    <
a href="<?php echo $url; ?>" title="<?php echo $name; ?>">
                        <
img src="<?php echo $img; ?>" width="auto" alt="<?php echo $name; ?>" /> <!--I suspect this line is wrong-->
                    </
a>
                </
li>
            
<?php endforeach; ?>
        
</ul>
</
div>
</
div>

I’ve tried countless ways to display the images in place of the category names but nothing seems to make the images appear. Currently with the above, the output is an empty ‘img src’ so there is clearly an error with what I’m trying (and probably a better way of achieving what I’m after).

Please could someone kindly point out what the problem is?

If it’s of any relevance, what I intend to do afterwards is then display the category images in a grid format (3 or 4 per line).

Many thanks in advance.

 
Magento Community Magento Community
Magento Community
Magento Community
 
zigojacko
Jr. Member
 
Total Posts:  13
Joined:  2010-09-05
 

Can anyone advise on this at all?

Just trying to call the sub category images/thumbnails instead of the names - I’ve spent hours searching and testing various finds but can’t seem to get it to work at all.

Any help greatly appreciated. Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
zigojacko
Jr. Member
 
Total Posts:  13
Joined:  2010-09-05
 

This has now been resolved…

We fixed this by applying the following:-

<?php
        
//gets all sub categories of parent category 'Brands'
        
$cats Mage::getModel('catalog/category')->load(6)->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
($categoriesSORT_STRING);
    
?>
        
<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>

With thanks to Chris @ Plymouth Software.

 
Magento Community Magento Community
Magento Community
Magento Community
 
squizeers
Member
 
Total Posts:  38
Joined:  2010-06-27
 

I am trying to do the same but using this extension http://webandpeople.com/articles/2011/03/custom-menu-magento-extension/ because I also want the static blocks to be enabled in the mega menu. How would i achieve the category thumbnails next to the category name in this?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top