Magento 添加分类下最新产品页
在每个一级分类下添加一个页面,显示该分类下的最新产品,实现这样的模块可以通过静态块来实现。具体步骤如下:
- 新建一个静态区块,用来显示最新的产品
{{block type="catalog/product_new" name="home.catalog.product.new" alias="product_homepage" template="catalog/product/new_furniture.phtml"}}
new_furniture.phtml 模板代码如下
<?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>
<?php $_columnCount = $this->getColumnCount(); ?>
<?php echo $this->getToolbarHtml() ?>
<div ></div>
<div class="category-products">
<?php $i=0; foreach ($_products->getItems() as $_product): ?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="products-grid">
<?php endif ?>
<?php if(in_array('3', $_product->getCategoryIds()))://'3'为所要现在最新产品的分类ID?>
<li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(240); ?>" width="220px" height="220px" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
<h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a></h2>
<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
<?php echo $this->getPriceHtml($_product, true, '-new') ?>
</li>
<?php endif ?>
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
</ul>
<?php endif ?>
<?php endforeach ?>
</div>
<?php endif; ?>
代码中这一句用在循环中过滤了不在这一分类下的产品
<?php if(in_array('3', $_product->getCategoryIds()))://'3'为所要现在最新产品的分类ID?>
- 在该分类(ID=3,比如叫 furniture)下新建一个二级分类,比如 Newly Added Furniture,显示方式为 static block
- 在要展示分类最新产品的链接加上链接这个静态区块的链接
<a href="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK).'furniture/newly-added-furniture.html' ?>" onclick="quick_over_new()">Newly Added Furniture</a></li>
转载请注明: 转载自Ryan 是菜鸟 | LNMP 技术栈笔记
如果觉得本篇文章对您十分有益,何不 打赏一下
本文链接地址: Magento 添加分类下最新产品页
本作品采用知识共享署名-非商业性使用 4.0 国际许可协议进行许可