首先在magento的主题目录/template/catalog/product中添加文件home.phtml,代码如下: <?php
$category = Mage::getModel('catalog/category')->load($this->getCategoryId());
$_productCollection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect(array('name', 'price', 'small_image'))
->addAttributeToSort('entity_id', 'desc')
->addAttributeToFilter('status', array('eq'=>1))
->addCategoryFilter($category)
->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds())
->joinField('inventory_in_stock', 'cataloginventory/stock_item','is_in_stock', 'product_id=entity_id', '{{table}}.is_in_stock=1')
->setPage(0, 3);
?>
<div class="base-mini" style="margin-top:12px;">
<div class="head">
<h4 style="background:url(<?php echo $this->getSkinUrl() ?>/images/icon_table.gif) no-repeat top left;">New Product</h4>
</div>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg" style="margin:5px;"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div style="padding:8px;">
<?php $_collectionSize = $_productCollection->count() ?>
<?php //$_columnCount = $this->getColumnCount(); ?>
<?php $_columnCount = 3; ?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php if ($i++%$_columnCount==0): ?>
<ul>
<?php endif ?>
<li style="float:left;display:inline;width:140px;margin:5px;">
<p>
<a href="/templates/default/"";<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>">
<img src="/templates/default/"";<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135, 135); ?>" width="135" height="135" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" />
</a>
</p>
<h5><a href="/templates/default/"";<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a></h5>
<?php echo $this->getPriceHtml($_product, true) ?>
</li>
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
</ul>
<?php endif ?>
<?php endforeach ?>
<div style="clear:both;"></div>
</div>
<?php endif; ?>
</div>
然后在最模板的magento后台管理系统的CMS > Pages > Home Page的内容中添加如下代码:
{{block type="catalog/product_list" template="catalog/product/home.phtml" category_id="3"}}
其中3为你要显示的产品分类ID号。
|