Magento限制主页中的产品数量

Magento限制主页中的产品数量,magento,Magento,我已在cms主页中添加了此代码{{block type=“catalog/product\u list”category\u id=“25”template=“catalog/product/list.phtml”} 我只想将要显示的产品数量限制为9个。我如何才能做到这一点?我认为没有一个值可以传递到block标记中来限制它。我建议创建一个新的list.phtml文件来限制它 让我快速看一下代码 嗯。如果要复制文件/app/design/frontend/default/default/temp

我已在cms主页中添加了此代码
{{block type=“catalog/product\u list”category\u id=“25”template=“catalog/product/list.phtml”}


我只想将要显示的产品数量限制为9个。我如何才能做到这一点?

我认为没有一个值可以传递到block标记中来限制它。我建议创建一个新的list.phtml文件来限制它

让我快速看一下代码

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

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

然后按如下方式对其进行编辑:

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; } ?>
LINE49:在foreach之后
第94行:其中$\u collectionSize被分配更改:
第97行:在foreach之后
无论是网格视图还是列表视图,它都应该满足您的需求

。。。不久,另一种方法

另一种方法是编辑List.php文件,该文件加载phtml文件显示的产品列表。“目录/产品列表”的块类型表示您需要该文件:

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

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


希望这有帮助

根据前面的答案,我似乎已经通过编辑List.php在第96行之后添加以下内容实现了这一点

return $this->_productCollection

            ->setPageSize($this->getProductsCount());

    }

    /**
     * Set how much product should be displayed at once.
     *
     * @param $count
     * @return Mage_Catalog_Block_Product_New
     */
    public function setProductsCount($count)
    {
        $this->_productsCount = $count;
        return $this;
    }

    /**
     * Get how much products should be displayed at once.
     *
     * @return int
     */
    public function getProductsCount()
    {
        if (null === $this->_productsCount) {
            $this->_productsCount = self::DEFAULT_PRODUCTS_COUNT;
        }
        return $this->_productsCount;
    }
在第43行之后加上这个

/**
 * Default value for products count that will be shown
 */
const DEFAULT_PRODUCTS_COUNT = 100;

/**
 * Products count
 *
 * @var null
 */
protected $_productsCount;
我从new.php获得了代码