Magento

eCommerce Software for Online Growth

Magento Forum

From setting up your store to managing your products, pages and promotions to generating detailed reports, the Magento User Guide empowers the user to utilize the platform for all of its vast capacity.
Available in eBook and Print formats – Download Now!!!
   
SOLVED: Almost there - categories on homepage working but images aren’t showing up
 
brendan.
Guru
 
Total Posts:  747
Joined:  2008-07-16
London, United Kingdom
 

hi,

sorry ive been really busy lately.
This line

<?php /* echo "Find this item->" */ ?>

is just some left over code i used

Give me a shout if you still need help
brendan

 Signature 

magento 1.3.1.2
PHP Version 5.2.6
http://www.getstuff.com.au

 
Magento Community Magento Community
Magento Community
Magento Community
 
clorne
Sr. Member
 
Total Posts:  149
Joined:  2008-01-10
London
 

I’ve just come across this thread as I needed to add images to sub-categories.

Brendan’s code works very well for me, many thanks for posting but, and this may be blindingly obvious, to get a return from

$_category->getImageUrl()

you have to add

->addAttributeToSelect('image')

to the function getCurrentChildCategories() in

app\code\core\Mage\Catalog\Block\Navigation.php

as

$collection->addAttributeToSelect('url_key')
            ->
addAttributeToSelect('name')
            ->
addAttributeToSelect('is_anchor')
            ->
addAttributeToSelect('image')
            ->
addAttributeToFilter('is_active'1)
            ->
addIdFilter($category->getChildren())
            ->
setOrder('position''ASC')
            ->
joinUrlRewrite()
            ->
load();

Sorry if this has already been mentioned

edit

This change to the core code may be overwritten when you update!

 
Magento Community Magento Community
Magento Community
Magento Community
 
brendan.
Guru
 
Total Posts:  747
Joined:  2008-07-16
London, United Kingdom
 

thanks clorne,

yeah, i would suggest putting this change into your local folder.
I have it setup so its not using the core but a local copy of the navigation.php

let me know if you need to know how to do this

cheers

 Signature 

magento 1.3.1.2
PHP Version 5.2.6
http://www.getstuff.com.au

 
Magento Community Magento Community
Magento Community
Magento Community
 
fenixf
Member
 
Total Posts:  35
Joined:  2008-04-08
 
brendan. - 31 October 2008 11:12 PM

thanks clorne,

yeah, i would suggest putting this change into your local folder.
I have it setup so its not using the core but a local copy of the navigation.php

let me know if you need to know how to do this

cheers

I’d be interested to know this. I’m having trouble rewriting multiple corefiles to the local folder.

Could you please share some info.

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
Weezers Gifts
Member
 
Total Posts:  71
Joined:  2008-11-08
PA
 

Hi all,

ok I have just implemented this into my site.  Everything works but the images.  It shows an image should be there, but all I get is the dreaded RED x

Any ideas or solutions?

Thanks much for this, this is good

 
Magento Community Magento Community
Magento Community
Magento Community
 
brendan.
Guru
 
Total Posts:  747
Joined:  2008-07-16
London, United Kingdom
 

hi,

whats your code look like.
Sounds to melike you havent added the relevant field

->addAttributeToSelect('image')

cheers

 Signature 

magento 1.3.1.2
PHP Version 5.2.6
http://www.getstuff.com.au

 
Magento Community Magento Community
Magento Community
Magento Community
 
Weezers Gifts
Member
 
Total Posts:  71
Joined:  2008-11-08
PA
 
clorne - 31 October 2008 11:21 AM

I’ve just come across this thread as I needed to add images to sub-categories.

Brendan’s code works very well for me, many thanks for posting but, and this may be blindingly obvious, to get a return from

$_category->getImageUrl()

you have to add

->addAttributeToSelect('image')


to the function getCurrentChildCategories() in

app\code\core\Mage\Catalog\Block\Navigation.php

as

$collection->addAttributeToSelect('url_key')
            ->
addAttributeToSelect('name')
            ->
addAttributeToSelect('is_anchor')
            ->
addAttributeToSelect('image')
            ->
addAttributeToFilter('is_active'1)
            ->
addIdFilter($category->getChildren())
            ->
setOrder('position''ASC')
            ->
joinUrlRewrite()
            ->
load();

Sorry if this has already been mentioned

edit

This change to the core code may be overwritten when you update!

Per this post this is what my code looks like:

$collection->addAttributeToSelect('url_key')
            ->
addAttributeToSelect('name')
            ->
addAttributeToSelect('is_anchor')
            ->
addAttributeToSelect('image')
            ->
addAttributeToFilter('is_active'1)
            ->
addIdFilter($category->getChildren())
            ->
setOrder('position''ASC')
            ->
joinUrlRewrite()
            ->
load();

 
Magento Community Magento Community
Magento Community
Magento Community
 
brendan.
Guru
 
Total Posts:  747
Joined:  2008-07-16
London, United Kingdom
 

ok, that looks cool

what about your phtml file your calling??

brendan

 Signature 

magento 1.3.1.2
PHP Version 5.2.6
http://www.getstuff.com.au

 
Magento Community Magento Community
Magento Community
Magento Community
 
Weezers Gifts
Member
 
Total Posts:  71
Joined:  2008-11-08
PA
 

Thanks for the help.

I am using the exact code you posted on page 2 post #28.  I created the exact same .phtml filename and uploaded it directly to where you said it needed to rest.

I followed that post to a “T” well I think I did, LOL.

But here is the code anyways:

<?php $_categories=$this->getCurrentChildCategories(); ?>

<div class="listing-type-list catalog-listing">
    
<?php foreach ($_categories as $_category): ?>
    
<table width="100%" border="0" cellspacing="0" cellpadding="0">
            
<?php if($_category->getIsActive()): ?>
            
<tr>
                <
td width="30%">
                    <
div class="listing-item">
                        <
div class="cat-box-text">
                        <
h6><a href="<?php echo $_category->getURL() ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>"><?php echo $this->htmlEscape($_category->getName()) ?></a></h6>
                        </
div>
                        <
div class="product-image">
                            <
a href="<?php echo $_category->getURL() ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>">
                                <
img src="<?php echo $_category->getImageUrl() ?>" width="100" alt="<?php echo $this->htmlEscape($_category->getName()) ?>" />
                            </
a>
                                
<?php /* echo "Find this item->" */ ?>
                        
</div>
                    </
div>
                
                </
td>
                <
td width="40%">
                    <
div class="listing-item">
                        <
div class="cat-box-text">
                        
<?php echo $_category->getDescription() ?>
                        
</div>
                    </
div>
                </
td>
            
<?php endif; ?>
            
</tr>
        </
table>
    
<?php endforeach; ?>
</div>

 
Magento Community Magento Community
Magento Community
Magento Community
 
brendan.
Guru
 
Total Posts:  747
Joined:  2008-07-16
London, United Kingdom
 

hmmm

looks ok. (code is the same per my current website)

Just to state the obvious you have an image assigned to the categories in question right?

Also you have “this” phtml file in the folder catalog\navigation

brendan

 Signature 

magento 1.3.1.2
PHP Version 5.2.6
http://www.getstuff.com.au

 
Magento Community Magento Community
Magento Community
Magento Community
 
brendan.
Guru
 
Total Posts:  747
Joined:  2008-07-16
London, United Kingdom
 

also try to refresh or disable cache

 Signature 

magento 1.3.1.2
PHP Version 5.2.6
http://www.getstuff.com.au

 
Magento Community Magento Community
Magento Community
Magento Community
 
Weezers Gifts
Member
 
Total Posts:  71
Joined:  2008-11-08
PA
 

looks ok. (code is the same per my current website) - OK Thats not the issue.

Just to state the obvious you have an image assigned to the categories in question right? - Oooops, my bad, no image is assigned for any category as I thought this was for random images from each category oh oh Sorry

Also you have “this” phtml file in the folder catalog\navigation - Here is my structure app/design/frontend/MY-TEMPLATE/theme/template/catalog/navigation/

 
Magento Community Magento Community
Magento Community
Magento Community
 
brendan.
Guru
 
Total Posts:  747
Joined:  2008-07-16
London, United Kingdom
 

no worries..

I would reckon its not returning images as you need to set images for each category

note: This script returns the images for the child categories.

Your location is all good.

cheers

 Signature 

magento 1.3.1.2
PHP Version 5.2.6
http://www.getstuff.com.au

 
Magento Community Magento Community
Magento Community
Magento Community
 
dan_w
Sr. Member
 
Total Posts:  290
Joined:  2008-01-04
 

brendan,
everything works great on my end. Thanks for the help. A real time saver. The only change that I made was to add a second category attribute called “second image”. That way I could have one main category image (for the actual category view page) and then a second category image to be called in the navigation. If anyone has any interest in defining how to add more than one category image, I’d be more than willing to help.

Dan

 
Magento Community Magento Community
Magento Community
Magento Community
 
brendan.
Guru
 
Total Posts:  747
Joined:  2008-07-16
London, United Kingdom
 

dan,

that secondary category image would be cool.

Can you share the code?

brendan

 Signature 

magento 1.3.1.2
PHP Version 5.2.6
http://www.getstuff.com.au

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
 
© Copyright 2010 Magento Inc.
Privacy Policy|Terms of Service
Magento Community Count
191338 users|759 users currently online|308856 forum posts