Hope someone can help me with this. I need to show 3 specific categories on my Magento home page. I have created a "list-homepage.phtml" file and have the following code in this file

<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php $open = $this->isCategoryActive($_category); ?>
$layer = Mage::getSingleton('catalog/layer');
if ($immagine = $this->getCurrentCategory()->getImageUrl()):
<div class="catalog-image">
    <div class="col-sm-4">
        <a href="<?php echo $this->getCategoryUrl($_category)?>">
        <img src="<?php echo $immagine ?>" alt="<?php echo $this->htmlEscape($this->getCurrentCategory()->getName()) ?>" class="img-responsive" />
<?php endif; ?>
<?php endforeach; ?>

And I have added this block to my home page in the back-end

{{block type="catalog/navigation" name="catalog.category" template="catalog/category/list-homepage.phtml"}}

The problem with this is that it displays all the categories I have, I just want to display 3, what do I have to do in order to achieve this?

Many Thanks for your help

4 Answers 4


You can put these widgets right into the content section of your homepage, I think it shows all products in the category without paging and you can choose list/grid mode. You just need to add it 3 times, once for each of the 3 category ids you want to include.

{{block type="catalog/product_list" name="product_list" category_id="73" mode="list" template="catalog/product/list.phtml"}}

I found this page in Google looking for a similar solution. This is the working solution I eventually came up with. Hope it helps the next person looking for how to achieve this!

1. Create a Static Block with the following code:
Note: You would want to change the ids accordingly. I named my block home-categories.

{{block type="catalog/navigation" name="catalog.category" template="catalog/category/teaser.phtml" ids="4,3,5"}}

2. In your template create a file teaser.phtml
Location: /frontend/default/{your-template}/template/catalog/category/teaser.phtml

3. Insert the following code in teaser.phtml

    $catIds = explode(',', $this->getIds());

    $categories = array();
    foreach($catIds as $catId) {
    $category = Mage::getModel('catalog/category')->load($catId); 
    $categories[$category->getName()] = array(
        'url' => $category->getUrl(),
        'img' => $category->getThumbnailUrl()

ksort($categories, SORT_STRING);
<ul class="categories">
    <?php if($category->getIsActive()): ?>
    <?php foreach($categories as $name => $data): ?>
            <div class="imageWrapper">
            <a href="<?php echo $data['url']; ?>" title="<?php echo $name; ?>" alt="<?php echo $name; ?>">
                <span class="name"><?php echo $name; ?></span>
                <span class="image"><img src="<?php echo $data['img']; ?>" alt="<?php echo $name; ?>" /></span>
    <?php endforeach; ?>
    <?php endif; ?>

4. Open up your template and call the block in the location you want.
For example in home.phtml, note that home-categories is the name you gave to the static block in step 1.

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('home-categories')->toHtml(); ?>

The problem is that all categories are returned via the function getStoreCategories. What you can do is create a widget that allows you to select your categories and then loads just the selected ones in the template.

Either that or a "quick" hacky fix you could add the ids directly in the template.

I would also suggest using a collection rather than a direct load.

  • Hi Thanks for the response, could you let me know how to create the widget and call this widget to display?
    – Davva M
    Nov 9, 2014 at 8:46
  • Try reading through magentocommerce.com/knowledge-base/entry/… Nov 9, 2014 at 8:51
  • Not really sure what to do, I am a bit lost to be honest!
    – Davva M
    Nov 9, 2014 at 9:01
  • Their is an option to insert a category link widget in my home page, but I need it to display an image. I found this here - stackoverflow.com/questions/6302897/…
    – Davva M
    Nov 9, 2014 at 9:07
  • Someone has suggested the below this - You'll need to stop the loop from completing the iteration if the current category is not wanted. One way you could do this is to note the ID of the 3 categories and use them to skip the loop iteration: code<?php $arr_cat_ids = array('2','4','6'); //array of wanted category ids foreach ($this->getStoreCategories() as $_category): $this_cat_id = $_category->getId(); if(!in_array( $this_cat_id, $arr_cat_ids)) continue; //if category is unwanted, skip to next iteration .... ?> - But I am not sure where I need to put this code in my orig code
    – Davva M
    Nov 10, 2014 at 12:12

Please add custom attributes using the following code.

$this->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'display_category_home', array(
'group'         => 'General Information',
'input'         => 'select',
'type'          => 'text',
'label'         => 'Display category homepage',
'backend'       => '',
'visible'       => true,
'required'      => false,
'visible_on_front' => true,
'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'source' => 'eav/entity_attribute_source_boolean',

Based on the custom field setting we display the category on the home page.

 $_categories = Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect('*')->addIsActiveFilter() ;
foreach ($_categories as $_category): ?>
    $cur_category = Mage::getModel('catalog/category')->load($_category->getId());
    $immagine = $cur_category->getImage();

    if($cur_category->getDisplayCategoryHome()) :
        <li class="item item-<?php echo $i++;?>">
            <h3 class="transform  cat-title font-20 letter-spacing"><?php echo $cur_category->getName();?></h3>
            <a href="<?php echo $cur_category->getUrl()?>" class="links">
                <?php if($immagine) :?>
                    <img src="<?php echo Mage::helper('addpeople_subcategory')->resizeImg($immagine,Mage::getStoreConfig('addpeople_tab_subcat/addpeople_subcategory/category_image_width'),Mage::getStoreConfig('addpeople_tab_subcat/addpeople_subcategory/category_image_width')); ?>" alt="<?php echo $this->htmlEscape($cur_category->getName()) ?>" />
                <?php else :?>
                    <img src="http://placehold.it/300x300" alt="<?php echo $cur_category->getName()?>">
                <?php endif ;?>
            <a href="<?php echo $cur_category->getUrl();?>" class="view-button transform font-20 letter-spacing">
            View Details
    <?php endif; ?>
<?php endforeach; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.