<
reference
name
=
"content"
>
<
block
type
=
"catalog/product_list"
name
=
"featured"
template
=
"catalog/product/list.phtml"
>
<
action
method
=
"setCategoryId"
><
category_id
>[category id here]</
category_id
></
action
>
</
block
>
</
reference
>
代码解释如下:
我们在magento后台新建一个分类,向这个分类中添加的产品会在首页显示。在magneto成功添加一个分类后,会给这个分类分配一个ID。红色部分“category_id”的值“3”既是此分类ID。“list.phtml”既是此产品列表的模板样式文件。
首页产品数量控制
产品列表也的产品是可以后台设置的,也可以xml中设置, xml设置的要不后台设置优先级高
有时我们设置首页的产品,数量上跟产品叶时有差别的,
这时到我们上面添加的block中添加如下代码来控制
<action method=”setColumnCount”><size>4</size></action>
<action method=”setCategoryId”><cid>4</cid></action>
<action method=”setCategoryId”><cid>4</cid></action>
控制代码是上面的,控制每行显示4个产品, 至于页面的产品个数就要就要修改phtml文件
<?php // Grid Mode ?>
<?php $_collectionSize = $_productCollection->count() ?>
<?php $_columnCount = $this->getColumnCount(); ?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php if($i>3): break; endif;?>
<?php if (($i++%$_columnCount==0)): ?>
这行就是控制显示个数的 <?php if($i>3): break; endif;?>
设置完了, 别忘了修改搜索显示产品, 修改方法类似, 找到搜索的block , 添加 <action method=”setColumnCount”><columns>4</columns></action> 就ok了, 不多说了
转载于:https://blog.51cto.com/junedesign/1240839