How To Display Random Products On Magento Store’s Home Page?

Showing random products on your store home page increases your chance to sell unsold products more often. Generally, store owners display featured products on home page which help them sell those quite frequently. Unfortunately, there are other products which aren’t featured, these product aren’t promoted enough to stand the competition. We recommend showing random products on home page to give other products (buried under deep links) a little promotional push. You will notice that a majority of our Magento Themes display random products on home page.

Displaying Random Products on Home Page

To display random products on your store’s home page in Magento Theme you need to follow the steps given below:

Step 1. Create a new file called random.phtml at app/design/frontend/default/Your_Theme/template/catalog/random.phtml then add the following code in that file

$_productCollection = $this->getLoadedProductCollection();
$number_of_products = $this->getNumProducts();
if (sizeof($_productCollection) < $number_of_products) {
	$number_of_products = sizeof($_productCollection);
$displayed_products = array();
foreach ($_productCollection as $_product) {
	$displayed_products[] = $_product;
$random_products = array();
if (sizeof($_productCollection) > 1) {
	$random_products = array_rand($displayed_products, $number_of_products);
} else {
	$random_products = array('0');
__('There are no products matching the selection.')?>

Random Products

class="last" >
htmlEscape($displayed_products[$random_products[$i]]->getName()); ?>

28) {echo substr($pname,0,25)."...";}else {echo $pname;}?>

getLocale()->currency(Mage::app()->getStore()-> getCurrentCurrencyCode())->getSymbol().$displayed_products[$random_products[$i]]->getPrice(); ?>

Step 2. Now put this line of code on your home page where you want to display random products. Please note that you can change the layout and visual appearance as per your theme’s requirements.

{{block type="catalog/product_list" category_id="3" num_products="8" template="catalog/random.phtml"}}

** Please note that the category id is specific to your store

I hope this will help you setup and display random products on your Magento store’s home page. Please leave us a comment and let us know if you face any difficulty implementing the code.

Join our Newsletter

Never miss the latest offers, voucher codes and useful articles delivered weekly in your inbox.