Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit number of products shown on homepage, list.phtml

Tags:

php

magento

block

I am trying to limit the number of products from a certain category to 4 on my homepage.

The code I am trying to do this with is:

{{block type="catalog/product_list" column_count="4" category_id="13" template="catalog/product/list.phtml"}}

Here are some of the things I have tried:

num_products="4"
limit = 4, limit="4"
count = 4, count="4"
_productCollection="4"
_productsCount="4"

I have made a copy of list.phtml thinking there might be a way to change it in there, but was unable to find out a way.

At the very top pf list.phtml is this code:

<?php
    $_productCollection=$this->getLoadedProductCollection();
    $_helper = $this->helper('catalog/output');
?>

And under grid view there is this:

<?php $_collectionSize = $_productCollection->count() ?>
    <?php $_columnCount = $this->getColumnCount(); ?>
    <?php $i=0; foreach ($_productCollection as $_product): ?>
        <?php if ($i++%$_columnCount==0): ?>

Any ideas on to limit the products either within the block or the template file?

like image 274
myladeybugg Avatar asked Dec 15 '22 13:12

myladeybugg


2 Answers

The quicker is replace column_count=4 by is_homepage=1

and in the phtml add this :

 <?php if($this->getIsHomepage() && $i==4) break; ?>

before this :

 <?php if ($i++%$_columnCount==0): ?>

Then you will have just 1 row on homepage (if 4 by row as I suppose) so total 4 products

like image 141
dagfr Avatar answered Dec 28 '22 17:12

dagfr


Try

 {{block type="catalog/product_list" limit="4" category_id="13" template="catalog/product/list.phtml"}}

See

  • http://www.mcnab.co/blog/e-commerce/magento/magento-displaying-products-in-a-static-block/
  • Magento Product Collection Limit via XML
like image 41
Renon Stewart Avatar answered Dec 28 '22 18:12

Renon Stewart