开发者

Magento - Display Individual Products

Is there an easy way in Magento to display individual products in a cms page without co开发者_Python百科pying 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.


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. :)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜