magento主页限制某个目录的产品显示数量
{{block type="catalog/product_list" name="product_list" category_id="7" template="catalog/product/list.phtml"}}
上面代码大家都知道是显示某个目录下的所有产品, 比如我这里的 category_id="7" 就是显示目录ID=7的所有产品。 如果要限制显示数量呢? 如果只显示这个目录以下的5个产品,怎么做?方法来了:
打开在此路径的文件: app\design\frontend\default\[your template name]\template\catalog\product
list.phtml 文件, 找到这一句:
<?php $i=0; foreach ($_productCollection as $_product): ?>
在这一句下面,加上:
<?php if($this->getIsHomepage() && $i==5) break; ?>
显示5个产品,按你的要求可以任意调整数量, 最后在插入block的地方,修改为:
{{block type="catalog/product_list" name="product_list" category_id="7" template="catalog/product/list.phtml" is_homepage=”1″}}
对, 增加 is_homepage=”1″ 这个属性,就会按你的要求只显示目录7的5件产品。
试试吧, gooooooooooood luck !