I am currently using the following code to display four products in a random order. It works, but I'd like to limit the results to a particular category or an array of categories. How would I go about implementing this change?
Thanks!
<?php $products = Mage::getModel('catalog/product')->getCollection();
$products->addAttributeToSelect(array('name', 'thumbnail', 'price')); //feel free to add any other attribues you need.
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
$products->getSelect()->order('RAND()');
$products->getSelect()->limit(4);
foreach ($products as $product) : ?>
<div class="three columns">
<div class="product_container ">
<div class="feat_prod_cont">
<h4 class="feature_product_title"><a href="<?php echo $product->getProductUrl()?>"><?php echo $product->getName()?></a></h4>
<a href="<?php echo $product->getProductUrl()?>"><img class="thumbnail" src="<?php echo Mage::helper('catalog/image')->init($product, 'thumbnail')->resize(93, 100)?>" alt=" "></a>
<div class="prod_details_featured">
<h3 class="price">$199.99</h3>
Free Shipping Free Stove
</div>
<div class="buy_btn"><a href="<?php echo Mage::helper('checkout/cart')->getAddUrl($product); ?>">ADD TO CART</a></div>
</div>
</div>
</div>
<?php endforeach; ?>