04 April

How to display New products in Magento


Hello Magento lovers!, have you ever wanted to display New products in your store by just setting the product  “Set Product as New from Date” within the product configuration in your Admin-panel?. It simple, luckily Magento provides php functions to do almost anything you wish, in this case we’ll use the  Mage::getResourceModel(‘catalog/product_collection’)  features:

We’ll create a template file called: new_products.phtml

The content would be:

$todayDate  = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);

$_productCollection = Mage::getResourceModel(‘catalog/product_collection’)
->addAttributeToFilter(‘news_from_date’, array(‘date’ => true, ‘to’ => $todayDate))
->addAttributeToFilter(‘news_to_date’, array(‘or’=> array(
0 => array(‘date’ => true, ‘from’ => $todayDate),
1 => array(‘is’ => new Zend_Db_Expr(‘null’)))
), ‘left’);

$now = date(“Y-m-d”);
$newsFrom= substr($_productCollection->getData(‘news_from_date’),0,10);
$newsTo=  substr($_productCollection->getData(‘news_to_date’),0,10);


<?php if(!$_productCollection->count()): ?>
<?php echo $this->__(‘There are no products matching the selection. Please provide a category ID.’) ?>
<?php else: ?>

<?php if ($now>=$newsFrom && $now<=$newsTo)?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<a href=”<?php echo $_product->getProductUrl() ?>”>
<img src=”<?php echo $this->helper(‘catalog/image’)->init($_product, ‘small_image’)->resize(110, 110); ?>” alt=”<?php echo $this->htmlEscape($_product->getName()) ?>” />
<?php endforeach ?>
<?php endif ;?>


Then you can call this template by adding a block call like this in your CMS content pages:

{{block type="catalog/product_list" template="catalog/product/new_products.phtml"}}


Hope you like it!. Cheers!

  • nauman

    it is not working…………..i want to display the images acc to date in specific block only……………..and my phtml file is in catalog/navigation

    • Aldo Pedro Poy

      The above code will work for listing catalog products only, that’s why it uses catalog/product_list block type.
      I’m not sure what you’re trying to accomplish, but you won’t get the product collection with this: $_productCollection=$this->getLoadedProductCollection(); in catalog/navigation types.

  • devendra411

    I followed your process but in my home page the new products are not showing. Can i know how to add?

Back to Top