How can I limit this block of code to display only 4 images from the category?

   <div class="note-msg">
   <?=$this->__('There are no products matching the selection.')?>

   <div class="home-spot">
   <div class="box best-selling">
   <table cellspacing="0">
   <?$i=0;$j=0; foreach ($_productCollection as $_product): ?>
   <?if ($i%2==0):?>
   <tr class="<?=($j++%2==0)?'even':'odd'?>">
   <a href="<?=$_product->getProductUrl()?>"><img src="<?=$this->helper('catalog/image')->init($_product, 'small_image')->resize(95, 95);?>" width="95" height="95" alt="<?=$this->htmlEscape($_product->getName())?>"/></a>
   <div class="product-description">
   <p><a href="<?=$_product->getProductUrl()?>" class="product-name"><?=$this->htmlEscape($_product->getName())?></a></p>
   <a href="<?php echo $this->getAddToCartUrl($_product) ?>" data-url="<?php echo $this->getAddToCartUrl($_product) ?>" data-id="<?php echo $_product->getId(); ?>" title="<?php echo $this->__('Add to Cart') ?>" class="btn btn-primary ajax-cart" ><i class="icon-cart"></i> <?php echo $this->__('Add to Cart') ?></a>
   <?if ($i%2!=0):?>
   <?php endforeach?>

I'm displaying the results like this here in my category

{{block type="catalog/product_list" category_id="22" products_count="4" columnCount="4" template="catalog/category/random.phtml"}}

however products_count="4" doesn't work. it just displays all images in that category. Is there some php I can used to control,


2 Answers 2


I think I figured it out but I'm not sure if it's the cleanest method. please advise as it works fine now with limitation. what I did was just add these lines of code to the top.

$_productCollection->load(); ?>

Now I can limit the number of products by adding a number to setPageSize(); However I'm not sure if I should be doing this or not. But it works great :) woo hoo!!!



{{block type="catalog/product_list" category_id="22" product_limit="4" columnCount="4" template="catalog/category/random.phtml"}}



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.