Magento - Display new products on the home page

If you've ever wanted to add new products in your Magento home page, it's fairly easy to implement. Go to "CMS" then "Manage Pages" and select "Home Page" from the list of pages. Now paste this code snippet to show products labeled as "new" on your front page:

{{block type="catalog/product_new" name="home.catalog.product.new" alias="product_homepage" template="catalog/product/new.phtml"}}

(Note that you must have some new products in your catalog for anything to show when you do this. This doesn't mean that you've recently added them; only products explicitly marked as new using "Set Product as New from Date" and "Set Product as New to Date" options in the "General" product information page in the admin tool will be shown.)

96 comments for Magento - Display new products on the home page

rashmi's picture

i have tried what is given...

i have tried what is given above but it does not work. please help.

Richard's picture

Hello Rashmi, Where are you...

Hello Rashmi,

Where are you adding it? What version of Magento are you using?

rawi's picture

i try at Magento ver. 1.5.0.1...

i try at Magento ver. 1.5.0.1 but no luck.

jennifer's picture

but how to control the number...

but how to control the number of products display in row and column? Say I want to have 8 new products to display at the main page, with 4 products in a row in 2 columns, is that possible?

Richard's picture

Hey Jennifer, It sure is! To...

Hey Jennifer,

It sure is! To display 8 items locate the file in your Magento installation (app/code/core/Mage/Catalog/Block/Product/New.php). Make a copy of this. You never want to modify Magento core files.

What are core files? Files located in app/code/core folder. If you have a need to modify one of them, you need to create a duplicate of that file with the same directory path to app/code/local. So for the New.php file you just made a copy of, copy it to app/code/local/Mage/Catalog/Block/Product/New.php. Now edit the file you just copied and make the following changes:

Change to the number of products to display:


const DEFAULT_PRODUCTS_COUNT = 8;

bhuvana's picture

hi I placed this above code...

hi

I placed this above code to CMS->Manage page->Home page

bit it does not working

new.phtml also here catalog/product/

Richard's picture

Hello bhuvana, Are you...

Hello bhuvana,

Are you pasting this into the Content field? This is where you paste it. Also, (Note that you must have some new products in your catalog for anything to show when you do this. This doesn't mean that you've recently added them; only products explicitly marked as new using "Set Product as New from Date" and "Set Product as New to Date" options in the "General" product information page in the admin tool will be shown.)

Eddie's picture

Thanks for the tip re:...

Thanks for the tip re: setting 'New From Date'.

Eddie

layus's picture

Hi Richard, I've tried the...

Hi Richard,

I've tried the above and it works although, in my template when i set more then 3 products it goes off the table, instead of adding a second row.

Any idea how to fix it? I've tried to set a limit on css, though it doesn't seem to work...

Richard's picture

Hey Layus, Thanks for your...

Hey Layus,

Thanks for your comment! The new products are outputted in tables so you can modify the source to suit your needs in /app/design/frontend/default/YOUR_TEMPLATE/template/catalog/product/new.phtml

Philip's picture

Thanks for this great tip....

Thanks for this great tip. Works but I am getting the block duplicated. Any ideas why this is happening?
Philip

Richard's picture

Philip, Happy this helped...

Philip, Happy this helped you. Check the products that you've specified as new.

simon browning's picture

That's a great tip, thank...

That's a great tip, thank you.

Would there be a way to get it to show new products from a certain category?

Thank you.

Simon

Richard's picture

Simon, Sure there is! Just...

Simon, Sure there is! Just marked the product in the category you want to display as new using "Set Product as New from Date" and "Set Product as New to Date" options in the "General" product information page.

simon browning's picture

Hi Richard. Thanks for...

Hi Richard.

Thanks for replying.

What I'd like to do is for example, on the "fruits" page display the newest fruits at the top of the page, followed by the regular fruits category; then on the "vegetables" page, display the newest vegetables at the top of the page, followed by the regular vegetables category.

Is that possible?

Thank you.

Simon

Plancton's picture

simon If you make a var_dump...

simon

If you make a var_dump of your product object variable in your template, you will see there is the category-ids field
I think you can use it to arrange your products using their category

Hucks's picture

i set the Set Product as New...

i set the Set Product as New from Date to yesterday and Set Product as New to Date to tomorrow
but nothing happens

Richard's picture

Hucks, Try clearing your...

Hucks,

Try clearing your cache and the Magento cache.

hucks's picture

cant get it to show more than...

cant get it to show more than 4 products

i have made the categories /app/code/local/mage/catalog/block/product copied NEW php to product folder, and changed the


const DEFAULT_PRODUCTS_COUNT = 5;

to


const DEFAULT_PRODUCTS_COUNT = 8;

and updated cache,

nothing happens?

Hucks's picture

ok i found the error if...

ok i found the error
if copying the displayed test its no good. u have to select the icons that pops up by hovering the text with the mousepointer and select the icon "copy to clipboard" then the code is right,

Tx for the code just what i needed. Smile

Liz Lee's picture

This worked great for me....

This worked great for me. Nice and easy. Thanks!

zhongzhen's picture

Thanks Richard. As I am a...

Thanks Richard.

As I am a magento developer, I am glad to read your post.

Justin's picture

Hello, great write up! It...

Hello,

great write up! It works for me, but I get duplicated blocks, and I don't know why... Any ideas? It doesn't matter what product I set up as NEW, still I get duplicated New Product blocks.

Richard's picture

Justin, are you sure you have...

Justin, are you sure you have only products explicitly marked as new using "Set Product as New from Date" and "Set Product as New to Date" options in the "General" product information page in the admin tool will be shown.

Daniel's picture

Hey Richard, this is great. ...

Hey Richard, this is great. However, when I put the code in my page, it overlaps my other design, is there a quick way to resize the block? I went into the new.phtml file and I can't find what I'm looking for.

Richard's picture

Daniel, You should be able to...

Daniel, You should be able to easily do this with CSS. Have a link for me to see?

Dan's picture

Scratching my head for a good...

Scratching my head for a good while trying to get more than 5 latest products to show up, your instructions worked perfectly - THANKS!

Elizabeth's picture

Thanks for this code. I have...

Thanks for this code. I have it working but with problems. The main problem is that all products are being displayed, even simple products with a "nowhere" display setting. Any suggestions as to how to display only products I've chosen to display in my "catalog,search"?

Richard's picture

Elizabeth, Just mark the...

Elizabeth, Just mark the product in the category you want to display as new using "Set Product as New from Date" and "Set Product as New to Date" options in the "General" product information page.

Elizabeth's picture

Richard, Thanks for your...

Richard, Thanks for your response. I always set these dates -- even before I figured out how to diplay new products.

Here's what I do and here's where the problem seems to lie: I start by creating a new, blank "configured" product. I fill in the form including the "Set Product as New from Date" and the "... New to Date." Then, in "associated products", I create the various simple products related to the configured product. Now all of the related simple products are set to "enabled" and "nowhere" but they automatically have the dates entered. It sure would be much more convenient for the "new products" function to select only from "catalog,search" enabled products instead of having to manually delete dates from all of my "nowhere" products.

Rustem's picture

I found the solution. Ok,...

I found the solution. Ok, what should we do to make visible the new products in your website(homepage or else where) :
Firstly, don't forget to sign out the product attributes "Set Product as new from date"-"Set Product as new to date"in general information. Try to edit "from date" before today.

Then if you want to see more than 5 product in your homepage :
don't forget about the core:
app\code\core\Mage\Catalog\Block\Product\New.php and edit the constant:


const DEFAULT_PRODUCTS_COUNT = 8;

This constant respond to how many products will be visible in your page.

Joanne Carr's picture

Nice post and thread! I seems...

Nice post and thread! I seems a lot of people are having problems with the homepage in Magento, which is quite a crucial part of the site! Thanks Richard for all your info on this.

The PLR Mart's picture

Hi Richard, Now its working...

Hi Richard,

Now its working fine in my site. Thanks for your help.

The new products title showing as "New Products", I would like to show as "New Products for October 2009"

can you please help me out.

With Regards
Venkat

Venkat's picture

Hi Richards, It seems you...

Hi Richards,

It seems you have deleted my comment. I sincerely posted my comment.

Anyhow i used the code you have mentioned above.

I have updated the code with 8 products. It is coming in single row and overlapping the right sidebar.

Help me to show 4 products a row and up to 5 rows please

site www.theplrmart.com

Regards
venkat

Richard's picture

Venkat, I didn't delete your...

Venkat, I didn't delete your comment just didn't get around to it Smile Your most likely going to change the code to do this since it's in tables. If you eliminate the table layout and replace with divs and a class that's a floated element, you can display it any way you want.

Venkat's picture

Hi Richard, Thanks for your...

Hi Richard,

Thanks for your response. I am sorry to ask you, can you tell me which file i need to change the code in order to display correctly.

Since i changed the products to 8 first to see 4 products in a row. That time i have right sidebar also, then the 8 products started showing overlay on the right sidebar and its displaying only 5 out of 8 in a single row.

As you are the expert please help me in this regard

Thanks in advance

Venkat

Raqueliii's picture

Hi! I have a problem with new...

Hi!
I have a problem with new products, i search in all answers but is a different problem. I add my products but it doesn't appear in new products, i update the date "Set Product as New from Date " and " Set Product as New to Date" and put the date of yesterday i both of them.
but today when i open the site the products doesn't appear. I don't know why sometimes the products appear and another one disappear. Thxs for all!

Richard's picture

Raqueliii, Did you try...

Raqueliii,

Did you try clearing your cache?

Kalamingo's picture

Hey Richard, Was wondering if...

Hey Richard,

Was wondering if there's a way to edit the coding, so that it shows the 10 most recently added products to the store without using the new from and to date flag. This will be very useful to me (and many others i would believe) because i don't update my site with new products very often, and lets say i normally flag a products as new for a max period of 7 days, after 8 days this coding wont show any products and my homepage will be lacking content.

I want it to always show the last 10 products regardless of whether its still flag as new. Hope you can help, thanks in advanced!

prits's picture

Hi there, I got the new...

Hi there, I got the new products on home page. But I have problem related to product url. Product url for new products is like http://sitename/catalog/product/view/id/priductID/s/productname and everywhere else it is like “http://sitename/productname.html”.

Can you please help me on this?

Richard's picture

prits, Check your settings...

prits,

Check your settings for the URL and clear the Magento cache.

Adrian's picture

What's up Richard, Wow, I'm...

What's up Richard,

Wow, I'm really impressed with this, man? I can't believe you actually take the time to respond to every reply personally. I hope karma is good to you - you deserve it Smile

Just wanted to say thanks for this small but helpful explanation. It has proven essential in a website I was making for someone and you saved me a whole bunch of time trying to reinvent the wheel. Not just your own post, but your replies to further inquiries as well! Thanks so much!

Keep up the good work man,
~Adrian

Richard's picture

Adrian, Thanks!...

Adrian, Thanks!

Jeannine's picture

Richard, you are a hero!...

Richard, you are a hero! Thank you so much for sharing this with us. I really am so happy to having found a solution to this issue Shock)

Big smile from DK

Richard's picture

Jeannine,...

Jeannine, Smile

Adrian's picture

Hey! A little note: I just...

Hey! A little note: I just noticed this little line in the "new.phtml" (/app/design/frontend/default/YOUR_TEMPLATE/template/catalog/product/new.phtml) of my theme:

5): continue; endif; ?>

This would make the loop stop after 5 fragments, even when DEFAULT_PRODUCTS_COUNT is set to any higher variable. I think I saw some people here having problem with this? This might solve their problem Smile Hope it helps!

Adrian's picture

Sorry, apparently that PHP...

Sorry, apparently that PHP line somehow didn't make it through your system. Could you fix it in the other comment for me, Richard? You can remove this one afterwards. Thanks!

The line I was talking about was:


<?php if ($i>5): continue; endif; ?>

gachaga's picture

thank you. it works like a...

thank you. it works like a charm. you've saved me.

Richard's picture

gachaga, Thanks!...

gachaga, Thanks!

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.