tags:

views:

101

answers:

2

Is there an easy way in Magento to display individual products in a cms page without copying and pasting the code from the catalog pages?

I have a blog on my magento store and sometimes I'd like to drop the listing for individual products into the posts.

+1  A: 

A code block in Magento is the best way to achieve this effect. If you look at your home page, that's how new products are generated dynamically:

{{block type="catalog/product_new" template="catalog/product/new.phtml"}}

If you created another block for a 'featured' item that took a product ID as a parameter, you could place that block on the static page and it would show that item. This page shows a brief example, but for the sake of being complete, I'll reproduce it here:

First create a new .phtml file with the following undercatalog/product/view/your_new_page.phtml

<?php
$productId = $this->getProduct_id(); 
$_product = Mage::getModel('catalog/product')->load($productId); //load the product
?>
<img src="<? echo Mage::helper('catalog/image')->init($_product, 'thumbnail')>resize(75, 75); ?>" alt="<?php echo $this->htmlEscape($_product['name']); ?>" border="0" width="75" />

Now simply add the following to your CMS Page or Block and adjust the product ID to the product Image you wish to view:

{{block type="catalog/product_new" product_id="1" template="catalog/product/view/your_new_page.phtml"}}

I'd probably tweak it a bit for readability if I used this on my store, but I'm also a bit overzealous in terms of using human-readable code. :)

Shaun
This worked but I noticed a problem. If I try and add this block twice to the same cms page but using different product id's it doesn't work. It shows the same product in each block. Is it possible to fix this?
a1anm
To display more than one product on a page using this method "catalog/product_view" should be used instead of "catalog/product_new"
a1anm
A: 

If you are working on Magento 1.4, you should take a look at widgets which do exactly what you want.

Hugues ALARY