How to get random product of a category in magento

27 Feb

1) To Show the list of all product of a category in random order just copy & paste the following code anywhere in your magento template files:

$catid = '12';
$category = new Mage_Catalog_Model_Category();
$category->load($catid); // this is your special offers category id!
$collection = $category->getProductCollection();
$numProducts = 5;
$collection->setPage(1, $numProducts)->load();
foreach($collection as $product) {
$product = Mage::getModel('catalog/product')->load($product->getId()); /* Load Products by ID*/
echo $product->getName();
echo $product->getShortDescription();

Posted by on Feb 27, 2012 in Magento


Tags: , , , ,

3 responses to “How to get random product of a category in magento

  1. biohazard cleanup job

    May 17, 2013 at 2:29 am

    Pretty great post. I just stumbled upon your weblog and wished to
    say that I’ve truly enjoyed browsing your blog posts. In any case I’ll
    be subscribing in your feed and I hope you write again very soon!

  2. Kicking a soccer ball

    Jul 20, 2013 at 11:47 pm

    Hi friends, its impressive paragraph on the topic of teachingand
    fully defined, keep it up all the time.

  3. Rock

    Apr 29, 2014 at 5:06 pm

    This is a short answer for large output… Thanks a lot


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: