List new & featured products in Magento homepage
I put this code in my home.phtml, but nothing is shown. I took this snippet of script from product/new.phtml :
<?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>
<?php $i=0; foreach ($_products->getItems() as $_product): ?>
<开发者_JS百科?php if ($i>15): continue; endif; ?>
<div>
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>">
<img class="home-page-img" src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->directResize(40,50,3); ?>" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />
</a>
</div>
<div>
<p><a class="product-name" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>)"><?php echo $this->htmlEscape($_product->getName()) ?></a></p>
</div>
<?php $i++; endforeach; ?>
<?php endif; ?>
How can I make it to display on the homepage? I have set products to be new products within certain date. Thank you!
You can do it by adding something like this to your layout update (CMS -> Pages -> Manage Content, select Home page, go to Design section)
<reference name="content">
<block type="catalog/product_new" name="home.catalog.product.new" alias="product_new" template="catalog/product/new.phtml" after="cms_page"/>
</reference>
精彩评论