add categories with images on homepage – magento

to add categories along with images on homepage

just add the code given below to your homepage from admininstration cms management.

{{block type="catalog/navigation" name="catalog.category" template="catalog/category/list.phtml"}}
Also you need to create a list.phtml file under “/app/design/frontend/default/default/template/catalog/category/list.phtml”
and add the below given code to it:
===========================================
<?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; ?>

================================================
About these ads

35 thoughts on “add categories with images on homepage – magento

      • hey sam,

        i need an help, i am using a Cms page as my home page for this i created an layout file in this file the container portion is static, where i putted a link to another CMS page where i want to show Category listing…as per iphone theme,,but on link it goes to that page but not showing anything in content,,,,,so how can i show Category listing in an CMS page???
        if u can add me Gtalk…..pls addd

  1. What can we do wrong. We made the file and added {{block type=”catalog/navigation” name=”catalog.category” template=”catalog/category/list.phtml”}}

    But there is nothing to see. No errors either

  2. Just add this code, but I think it’s only applicable for the “head” categories and not the sub categories. I have my navigation under the producten page. Is it possible to show the sub categories on the homepage?
    Grtz,
    Erwin

  3. Hi, thanks for this code, it works well. But i would like to add a static bloc between the homepage text and the {{block type=”catalog/navigation” name=”catalog.category” template=”catalog/category/list.phtml”}}, and a static bloc with css design, how to do it??

  4. For all who is seeking a real answer
    this is your php file save it in “/app/design/frontend/default/default/template/catalog/category/Your_file_name.phtml”
    getCurrentCategory();
    $collection = Mage::getModel(‘catalog/category’)->getCategories($_category->entity_id);
    $helper = Mage::helper(‘catalog/category’);
    ?>

    {{block type=”catalog/navigation” name=”catalog.category” template=”catalog/category/list.phtml”}}

    getIsActive()):?>
    load($cat->getId());
    $_img = $cur_category->getImageUrl();
    ?>

    <a href="getCategoryUrl($cat);?>”>
    <img src="” title=”$cat->getName()”/>
    getName();?>

    and you may call it from placing the following line in editor

    {{block type=”catalog/navigation” name=”catalog.category” template=”catalog/category/Your_file_name.phtml”}}

    • Are you sure you have images set up for your categories? The following condition is clipping out categories w/o images:

      if ($immagine = $this->getCurrentCategory()->getImageUrl()):

      Replace it with

      $immagine = $this->getCurrentCategory()->getImageUrl();

      and remove endif; in order to display all categories regardless if they have images or not. Also the following line is useless:

      isCategoryActive($_category); ?>

    • I doesn’t work for me , Rocky its page not found
      Samsami2u , please make it clear that do we need to create any static block ,
      Please reply i am new to the magento

  5. What if you have a custom template? E.g. i’ve made a custom template for Magento, and its called trex. The file for the list will be found in app/design/frontend/default/trex/template/catalog/list.phtml right? Do i have to change anything so the code below calls for the catalog/category/list.phtml in the trex template?

    {{block type=”catalog/navigation” name=”catalog.category” template=”catalog/category/list.phtml”}}

  6. Hello, Samsami2u,

    I’m using the above code to get the image from my active category on the homepage.
    I would like to know if i can show the “active from date” and “active till date” as well. I’ve tried to put in this getCustomDesignTo()?> instead of the getName()?> .

    I’ve got no errors but it isn’t showing.

    Can you give me some advise?

    Thanks!

  7. Hi it works perfectly on magento 1.7.0.2 the only question I have is:
    what if I want to display a custom picture instead of the category?
    Thank you

  8. Hi,

    Could you please elaborate where exactly this line of code should go in ?
    {{block type=”catalog/navigation” name=”catalog.category” template=”catalog/category/list.phtml”}}

    I am a newbie to magento as well as php.

    Thanks in advance

  9. For those whom it is not working, its been like 4 years since I have posted this article. Since then magento has changed a lot and also I have not been working with magento. If you have some specific issue I can help you with investing my personal time.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s