Magento set limit for products

magento

Below code will call limit products with function getLoadedProductCollection().
Here, I use function setPageSize() and I set a variable is numbers of products need to show.

I get an example is file template/catalog/product/list.phtml in default of Magento Enterprise 1.14.1.0

Add after this line code in template/catalog/product/list.phtml:

$_productCollection=$this->getLoadedProductCollection();

By this code:

$_productCollection = $this->getLoadedProductCollection();
///////////////////
$numberItems = 5; //set 5 products
if(is_numeric($numberItems) && $numberItems > 0) {
$_productCollection->setPageSize($numberItems);
}
///////////////////

 

After, clear all cache, reload and see result

catalog

Have a nice day!

One thought on “Magento set limit for products

Comments are closed.