Friday 6 July 2012

Show Category With Image in Magento

For adding of  categories with its  images on homepage od magento  we have to add    block from admininstration cms management either by just putiing the code given below  or making the static block .

{{block type="catalog/navigation" name="catalog.category" 
template="catalog/category/list_category.phtml"}}
 
 And also you need to create a list.phtml file under “/app/design/frontend/default/default/template/catalog/category/list_category.phtml”

<?php foreach ($this->getStoreCategories() as $_category): ?>
 <?php $open = $this->isCategoryActive($_category); ?>
 <?php
$cur_category=Mage::getModel('catalog/category')->load($_category->getId());
$layer = Mage::getSingleton('catalog/layer');
$layer->setCurrentCategory($cur_category);
if ($immagine = $this->getCurrentCategory()->getImageUrl()):
 ?>
<div style="float:left; padding-right:30px; text-align:center;">
 <div class="linkimage">
 <p>
 <a href="<?php echo $this->getCategoryUrl($_category)?>">
 <img src="<?php echo $immagine ?>"
  alt="<?php echo $this->htmlEscape($this->getCurrentCategory()->getName()) ?>" width="135" height="135" />
 <?php echo $_category->getName()?>
    </a>
    </p>
    </div>
    </div> <?php endif; ?>
    <?php endforeach; ?>

9 comments:

  1. it's grt code bro thanks posting this
    but here is some problem in image and thumbnail image
    if we need 2 banner image then it's give some problem
    for that
    i just update the base code

    ReplyDelete
  2. if ($immagine = $this->getCurrentCategory()->getThumbnail()):

    < src="" width="260" height="235" />

    ReplyDelete
  3. Hi Abid,

    I am Chhatrapal Singh Shekhawat your Neighbour from Churu Rajasthan


    I have your file in my /app/design/frontend/default/my theme folder/template/catalog/category/list_category.phtml”

    and i have problem to see categary list on my home page can you help me please i am waiting your positive response

    ReplyDelete
  4. Hi

    Thanks for the code. It works great and very simple.

    It shows just the main categories though. Is there any way to modify the code so it shows sub-categories, or even better, a way to select categories?

    Thanks
    Nancy

    ReplyDelete
  5. Hi Abid,

    I used the code and it worked.. I don't know much at all about php coding, a little html and css and a vague understanding of the Magento file structure etc. So thanks very much. Managed to get Catalogue main images with links to show up on shop homepage instead of the all of the products... Needs a little css I think because the last two right hand side images and not aligned properly with the rest. (Images in two columns) About 10 pixels out.
    Thanks
    Tracey

    ReplyDelete
  6. the code is superb.. very help full...!! but i want to display category desciption... plzzz help...!!!

    ReplyDelete
  7. The blog was absolutely fantastic! Lot of great information which can be helpful in some or the other way. Keep updating the blog, looking forward for more contents...Great job, keep it up..
    magento development company in bangalore 

    ReplyDelete
  8. hi,

    I have added this code in my website but it did not work properly.

    Can you please help me? how Can i show the category with images on my home page.

    Code :
    {{block type="catalog/navigation" name="catalog.category" template="catalog/category/list.phtml"}}

    Thanks

    ReplyDelete

Note: only a member of this blog may post a comment.