What I got: I have Magento CE installed

What I need: I want to show a few recent products for each category in my home, like they've done in Instacart's home. Instacart store home

How do I picture the solution: This view is way similar to the one generated by the New Product List, however the New Product List do not accept category filtering. Therefore, I'd want to edit the New.php file to accept category filtering.

What I have tried: I have tried to edit a copy of New.php in the [app/code/local/Mage/Catalog/Block/Product] directory, to alter the _beforeHtml function, as showed in this StackOverflow question, as well as updating both _beforeHtml and getCacheKeyInfo while creating the new getCategory support function as proposed in this StackExchange question. Neither seems to work for me, changes in the getCacheKeyInfo makes the block disappear altogheter, while other changes ignore the category_id filter in the block call.

2 Answers 2


Create a local.xml under app/design/frontend/yourpackage/yourtemplate/layout/local.xml code of this file are

< ?xml version="1.0"?>
<layout version="0.1.0">

       <reference name="content">
            <block type="core/template" name="my_default_home_page" template="cms/home.phtml"/>


and create home.phtml under app/design/frontend/yourpackage/yourtemplate/template/cms and code is this file below

here the code

foreach($catgorcollection as $category ){

$todayStartOfDayDate  = Mage::app()->getLocale()->date()

        $todayEndOfDayDate  = Mage::app()->getLocale()->date()

        $collection = Mage::getResourceModel('catalog/product_collection'); 
$collection = $this->_addProductAttributesAndPrices($collection)
            ->addAttributeToFilter('news_from_date', array('or'=> array(
                0 => array('date' => true, 'to' => $todayEndOfDayDate),
                1 => array('is' => new Zend_Db_Expr('null')))
            ), 'left')
            ->addAttributeToFilter('news_to_date', array('or'=> array(
                0 => array('date' => true, 'from' => $todayStartOfDayDate),
                1 => array('is' => new Zend_Db_Expr('null')))
            ), 'left')
                    array('attribute' => 'news_from_date', 'is'=>new Zend_Db_Expr('not null')),
                    array('attribute' => 'news_to_date', 'is'=>new Zend_Db_Expr('not null'))
            ->addAttributeToSort('news_from_date', 'desc')


first copy new.php file from app\code\core\Mage\Catalog\Block\Product\New.php to app\code\local\Mage\Catalog\Block\Product\New.php

now edit this file near line 88

protected function _getProductCollection()
// put  here code line is near 122 
$category = Mage::getModel('catalog/category')->load($this->getData('catagory_id'));
// code end
return $collection;

now add block in home page cms {{block type="catalog/product_new" catagory_id="28" template="catalog/product/new.phtml"}} here 28 is my category id put multiple blcok like above and chanege catagory_id for diffent categories

please vote

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.