3 easy steps to add products to the Magento Home Page (or any CMS page)

I wanted to add a small selection of products to the Magento homepage, and I thought I’d quickly write up how I did it, because it brings together a few little tidbits from around the net. This solution will use a specific category which can either be an actual category with a few products in it (e.g. specials), or one you created specifically for displaying on the home page (let’s call it ‘home page featured’). It takes only 3 simple steps as shown below.

Step One

First add this to your CMS page where you want the products to appear (I’ll assume from here on out that it’s your cms home page):

{{block type="catalog/product_list" category_id="YOUR_CATEGORY" template="catalog/product/list.phtml"}}

Notice you have to put your chosen category id in the code where I have YOUR_CATEGORY as a placeholder.

This will make the products show up but you’ll notice two annoying things probably. The first is the category you made for featuring showed up in your navigation menu and second the toolbar for paging and sorting may show up, which you won’t want if you just have 3-6 products featured on your home page.

Step Two

So the second step is to hide away those toolbars on the cms homepage. We are using a standard magento template to display the prodcts (that’s the template="catalog/product/list.phtml" from above) so it’s cleaner and better for upgrading/template maintenance if we do not go and edit it just to remove the toolbars. Instead let’s just throw a display:none in just for this page on the two css classes that matter, the .pager and .sorter.

That will look like this, notice it is specifically the cms-home page that is being styled, you’d do the same for your page:

.cms-home .pager, .cms-home .sorter {
        display: none;
}

So this hides them away, the html is still there, but no one will see it. The template is unchanged, and easily upgradeable.

Now the last issue is the nav menu, if you chose to use a new category especially for home page featured products then you won’t probably want that showing up in the nav menu.

Step Three

The 3rd and final step is a simple config option to disable categories from showing in the menu. It will allow you to have categories that can be used for display in parts of the store, but that will not show on the menu. The Is Active option is what you need to set to ‘no’ in order to hide the faux category.

So we put all of those simple 3 steps together and we get this (you can click through for the full size image):

RealNappiesUSA Magento Home page showing the simple category display technique

RealNappiesUSA Magento Home page showing the simple category display technique

You might also be interested in:

  1. Why are my Magento products not showing up?!
  2. MageSpeedTest.com with Siege – Performance Testing Magento Made Easy
  3. 10 Steps to Magento Ecommerce on a (small) Budget
  4. Removing the Compare function in Magento, the easy way
  5. Magento and Amazon’s CloudFront CDN – The Easy Way

33 Responses to “3 easy steps to add products to the Magento Home Page (or any CMS page)”

  1. needshelpwithmagento October 23, 2009 at 1:09 am #

    where do we put the code

    .cms-home .pager, .cms-home .sorter {
    display: none;
    }

    on the CMS of the homepage?

  2. Ashley October 23, 2009 at 4:29 pm #

    Hi, the code goes in your css file, or the default css file if you have not added your own. Though I recommend you do!

  3. Dan November 19, 2009 at 9:08 am #

    The hidden category method works well for selecting frontpage products, only the css does not hide the toolbars.

    In my cms settings the home page reference is ‘home’. I have tried using

    .cms-home .pager, .cms-home .sorter {
    display: none;
    }

    and

    .home .pager, .home .sorter {
    display: none;
    }

    in boxes.css, but nothing happens.

    Does this method not work with 1.3.2.4, or am i doing something wrong?

  4. Ashley November 19, 2009 at 11:09 am #

    Hi, you could post/email a link to your page and I’ll take a quick look. The tool I use to take a quick look is called firebug, it’s a plugin for firefox that by the sounds of things you don’t have. If you do, you can inspect any html element and check what css styles are (or are not) being applied. You can actually do about 1000 other useful web developer things with firebug, it really is the number one must have tool and I can’t recommend it to you enough.

  5. Dan November 19, 2009 at 1:50 pm #

    Not to worry – since posting I duplicated the ‘list.phtml’ file, removed the toolbar references in that, then referenced the new file in my cms block.

    Ta for the firebug recommendation – ill look into it.

  6. Andrew Jordan December 9, 2009 at 11:12 am #

    Where are you entering this code? I’m a NOOB to all of this stuff.

    I got it to show products but way off the screen by adding step 1 to my cms file under Content in the admin panel, but i can’t figure out what files you are altering for step 2 and what exactly step 3 is supposed to do?

  7. Ashley December 9, 2009 at 4:36 pm #

    We were all noobs at one stage.
    Step 1 goes in the CMS Page content itself – you input it using the Manage Pages section of Magento CMS – it’s layout might depend on the number of columns you’re using? Post a link to the page if you want me to take a quick look.
    Step 2 goes in a CSS file in the skin directory, but if that sounds too hard, you can put it at the top of your CMS page too in a style block
    Step 3 is just done using the Manage categories screen.

  8. simon January 27, 2010 at 6:59 am #

    Dear, Ashley i want to add left menu of subcategories at my product page but i could not got the solution if u could help me to tackle this problem i will be highly thankful.i will send u a screen shot if u give me your email.
    i am waiting your reply.
    thanx in advance
    simon

  9. Ashley January 27, 2010 at 11:12 am #

    Hi, Simon – thanks for getting in touch, I suggest searching on Google for magento code that will show products from the same category on the product page. Then once you have that working, tackle the next step, which is to slightly modify that code to grab sub categories of the current products category and list those.

  10. simon January 28, 2010 at 6:38 am #

    thanx Ashely for your precious time but i did the part of main menu.my store main menu working properly but after lots of searching in google still i could not got the solution i am using 1.3.2.4 version of magento if u colud give me some code or links which will help me.

  11. simon January 28, 2010 at 6:59 am #

    which will help me displaying subcategories in left menu

  12. shawn January 28, 2010 at 9:47 am #

    example in your cms home page

    .cms-home .pager, .cms-home .sorter {
    display: none;
    }

    {{block type=”catalog/product_list” category_id=”4″ template=”catalog/product/list.phtml”}}

  13. Ste February 8, 2010 at 5:44 pm #

    Hi,
    only pager is hide, but sorter is still there!!!
    Any help?
    i am waiting your reply.
    thanx in advance

  14. Gtech UK February 18, 2010 at 5:26 am #

    Thank you for posting. I would like to create page where after clicking on image product is added to basket. Is that possible?

  15. syberplace March 18, 2010 at 4:28 am #

    I create a magento theme. In that, in the navigation menu the sub categories are not showing in the frontend when iam opening the website..

    can u give me the solution for this kind of problem..

  16. Mike Berg April 6, 2010 at 6:48 pm #

    I am working on this site: http://www.cavellequipment.com/ and I need to get just the grid of category thumbs/links from this page: http://www.cavellequipment.com/index.php/products.html onto the homepage. Would I use a similar code to do this?
    Thanks!
    -Mike

  17. Ashley April 7, 2010 at 1:19 pm #

    Hi, I think you’d use a category list, not a product list – but same principle. Let us know how you get on.

  18. Tony's Domestic Appliance Spare Parts April 15, 2010 at 10:43 am #

    This is a great article on how to use code snippets in design. I purchased a magento template for my first magento site that gave me great insight on how to use xml markup. For those still following along may be interested in a code hack for finding category ids. It is provided by my own magento host at http://www.sonassi.com/knowledge-base/quick-script-to-export-categories-with-ids/.
    Keep up the good work.

    regards Tony

  19. Dave May 13, 2010 at 9:35 pm #

    Looks like this no longer works in version 1.4. Any idea how to list products from a category in this new version?

  20. justin snyder May 14, 2010 at 2:52 am #

    How do I add category products to a .phtml file?? I have looked everywhere without luck! Thank you.. i want to add category products to the search results page.

  21. raj September 9, 2010 at 11:34 pm #

    how to show product of various category on the homepage

  22. Your Name December 24, 2010 at 5:11 am #

    ths…

  23. Janeta February 17, 2011 at 11:45 am #

    Works great for me, thanks. The only thing is how do I display 4 products in a row and how do I limit the number of new products? Would be very grateful for a help.

  24. Cait May 19, 2011 at 3:46 pm #

    My products are showing from my correct category on my home page, and I uploaded the images on each of the products through Magento. However, they are not showing up on the home page product preview slider or on the product page. Any ideas on what I’m doing wrong?

  25. Ksauce May 19, 2011 at 11:56 pm #

    To hide the sorter and remove the small blank spaces, try this css instead.

    .cms-home .toolbar, .cms-home .toolbar-bottom {
    display: none;
    }

    without the spaces in the style tags.

    It hides the entire toolbar element that contains the sorter and pager.

    For those who don’t know where to put this:
    Put it at the top of your “content” section for your homepage (this is the lazy way).

    I’ve only tested this in 1.5 but it should work for all versions that use the div classes toolbar and toolbar-bottom.

  26. GSP June 14, 2011 at 4:24 am #

    Hi

    where we need to add

    {{block type=”catalog/product_list” category_id=”YOUR_CATEGORY” template=”catalog/product/list.phtml”}}

    if in css file – where is it

    Thanks

  27. Jhon October 21, 2011 at 10:47 am #

    I want to show paging on home page list.
    Is that possible ?

  28. magento November 21, 2011 at 10:11 pm #

    i want to display the products of different categories using multiple slider….

    {{block type=”catalog/product_list” category_id=”YOUR_CATEGORY” template=”catalog/product/featured.phtml”}}

    by using this code i do get 1 slider of first category. bt by repeating this code my slider vanished and the products are lined up vertically…..

  29. David November 26, 2011 at 1:56 am #

    Ashley…..you save my life!!!!, hahaha :)

    Thank you for your guide, for your help, for your site!!!

    I could finally delete the toolbar on my home page of site!!

    I spent at least 3 days for understand how to do looking around….then finally i found your site!

    Thank you again
    David, from Italy

  30. David November 26, 2011 at 3:41 am #

    ….anyway i found that it works on Internet Exploer, but not on Firefox… is it normal?

  31. Gloopy December 28, 2011 at 1:42 pm #

    Thanks for this guide, just implemented it on my site

  32. Daniel Watson January 16, 2012 at 8:40 am #

    Really great post. As i implement this in my site and it really works.
    Thanks for sharing such a useful stuff.

  33. shaikh zafar January 20, 2012 at 7:54 am #

    Hi,
    I try this to add products on My home page but it shows error. can anyone please tell me what i have to do?

Leave a Reply:

Gravatar Image