Php – How to get products from a particular category in magento ecommerce


I'd like to get a list of random products from the same category as the current product for displaying within the product view – so far all I've dug up is

Magento products by categories

Does anyone know how to do this?

Best Solution

You basically load up the category, get the Product Collection and then filter appropriately.

$products = Mage::getModel('catalog/category')->load($category_id)
 ->addAttributeToFilter('status', 1)
 ->addAttributeToFilter('visibility', 4)
 ->addAttributeToFilter('special_price', array('neq' => ""))
 ->setOrder('price', 'ASC')