Magento – modify list.phtml to show only a limited number of products on home page

list.phtmlmagento-1.9product-list

On the home page, I am trying to display70 only 6 random products on one row, from a category (id 24) that has 70 products. And randomly changed each time the page gets re-loaded.

The only method that works so far is from the following link
http://www.magikcommerce.com/blog/random-products-magento-home-page/
and using
{{block type="catalog/product_list" category_id="24" num_products="6" template="catalog/random.phtml"}} in home CMS.
Problem is that this is not responsive.

So I have been trying to use the rwd/default/template/catalog/product/list.phtml
with the following code in home cms without success.
{{block type="catalog/product_list_random" category_id="24" num_products="6" column_Count ="6" template="catalog/product/list.phtml"}}

With the above in home cms
1) it does not display products from id 24.
2) Second I can't control the the number of products it displays.
3) I can't find block type="catalog/product_list_random" any where. Is that a file?

ps. using rwd template files

Best Answer

Looking at the block 'catalog/product_list_random` you can only set the number of products to retrieve from the store.

In order get the desired result you want you could create your own custom block that does the following:

$collection = Mage::getResourceModel('catalog/product_collection');
Mage::getModel('catalog/layer')->prepareProductCollection($collection);
$collection->getSelect()->order('rand()');
$collection->addStoreFilter();
$collection->addCategoryFilter($this->getCategoryId())
$numProducts = $this->getNumProducts() ? $this->getNumProducts() : 0;
$collection->setPage(1, $numProducts);

$this->_productCollection = $collection;
Related Topic