Magento限制首页中产品的数量 [英] Magento Limit Number of Products in Home page

查看:56
本文介绍了Magento限制首页中产品的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已在cms主页中添加此代码{{block type="catalog/product_list" category_id="25" template="catalog/product/list.phtml"}}

I have added this code {{block type="catalog/product_list" category_id="25" template="catalog/product/list.phtml"}} in cms home page

我只希望将最多只能显示九个类别的产品限制在该类别中.我该怎么做?

I want to limit no of products to display to nine to this category only.How can i do that?

推荐答案

我认为您没有可以传递给block标签的值来限制它.我建议创建一个新的list.phtml文件,将其限制在那里.

I don't think there is a value you can pass into the block tag to limit it. I would suggest making a new list.phtml file that limits it there.

让我快速地看一下代码.

Let me look at the code real quick.

好的.如果要复制文件/app/design/frontend/default/default/template/catalog/product/list.phtml

Ok. If you were to copy the file /app/design/frontend/default/default/template/catalog/product/list.phtml

/app/design/frontend/default/default/template/catalog/product/list-limit.phtml

/app/design/frontend/default/default/template/catalog/product/list-limit.phtml

,然后按如下所示对其进行

and then edit it as follows:

LINE49: After the foreach
<?php if($_iterator >=9) { break; } ?>
LINE94: Where $_collectionSize is assigned change to: 
<?php $_collectionSize = main(9, $_productCollection->count()) ?>
Line97: After the foreach 
<?php if($i >= 9) { break; } ?>

无论网格视图或列表视图如何,它都应达到您想要的效果.

It should achieve what you desire regardless of Grid or List view.

...不久是另一种方法...

... shortly an alternative method ...

另一种方法是编辑List.php文件,该文件将加载phtml文件显示的产品列表. "catalog/product_list"的阻止类型表示您需要以下文件:

The other way would be to edit the List.php file that loads the product list that the phtml file presents. Block Type of 'catalog/product_list' means you need the file:

/app/code/core/Mage/Catalog/Block/Product/List.php

/app/code/core/Mage/Catalog/Block/Product/List.php

在该处,您将看到方法getLoadedProductCollection,该方法调用_getProductCollection.可以编辑该代码以过滤/限制退回产品的数量.不过,您可能想要复制该文件,并更新页面中的阻止链接.不要在名称下添加下划线,因为这将要求文件放在子目录中.

In there you will see the method getLoadedProductCollection, which calls _getProductCollection. That code could be edited to filter/limit the number of returned products. You would want to make a copy of that file though, and update the block link in your page. Don't add underscores to the name, as that will require the file be put in a subdirectory.

希望这会有所帮助.

这篇关于Magento限制首页中产品的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆