Magento Featured Item Based on Current Category

StA1L3r

New Member
I'm using the following code in my view.phtml file to display a random featured product:\[code\] <?php$catId = $this->getCat_id();$cat=Mage::getModel("catalog/category")->load($catId);$prodCollection = $cat->getProductCollection();$pids=array();foreach($prodCollection as $product){ array_push($pids,$product->getId());}$randProductId=array_rand($pids);$product = Mage::getModel('catalog/product')->load($randProductId);$product->getName();?><div class="catalog-h-price"> <img src="http://stackoverflow.com/questions/10559476/<?php echo $product->getImageUrl();?>" height="64" width="64" /><?php echo $product->getName();?><br /><span class="price"><sup>$</sup><?php echo number_format($product->getData('price'), 0); ?></span> <span class="msrp">U.S. MSRP</span><a href="http://stackoverflow.com/questions/10559476/#"><a href="http://stackoverflow.com/questions/10559476/<?php echo $product->getProductUrl();?>"><img src="http://coloresg.com/skin/frontend/default/modern/images/view-now.gif" width="36" height="28" /></a> </div>\[/code\]Currently it shows a random product from the entire catalog; I would like to know how adjust to pull only from current category.Thanks,-Sam
 
Back
Top