Aug 282011
I’ve tried asking this over on Magento’s forums, but it’s slow and the answer I got isn’t really working.
On my store front’s home page, I want to display the 5 most recent products added to the store - regardless of what category they belong to.
The only helpful bit of info I got is to create a new file called new_p.phtml that looks like this:
<?php
$_products = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('name');
Mage::getModel('catalog/layer')->prepareProductCollection($_products);
$_products->getSelect()->order('entity_id desc');
?>
<h2 class="subtitle"><?php echo $this->__('New Products') ?></h2>
<?php $i=0; foreach ($_products->getItems() as $_product): ?>
<ol class="products-grid" id="products-grid">
<?php if ($i>4): continue; endif; ?>
<li class="item">
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135) ?>" width="135" height="135" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" /></a>
<h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a></h3>
<div class="actions" style="border: solid 3px #0F0">
<?php if($_product->isSaleable()): ?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
<?php endif; ?>
</div>
</li>
<?php $i++; endforeach; ?>
</ul>
and put it in here:
appdesignfrontenddefaultmy_interfacemy_theme templatecatalogproductnew_p.phtml
Edit:
Added this line to the CMS > Home Page > Layout Update XML:
<reference name="content"><block type="catalog/product_new" name="product.new" template="catalog/product/new_p.phtml" /> </reference>>
Well… this grabs one random product. Not 5 products, and it grabs one random product (in this case, item 63 out of 125) instead of the latest product.
Please help!