Magento - Four Products on Homepage - Random Order - Foreach Loop -
i'm trying 4 random products on homepage using php within tpl file i've created. i'd able format products in foreach loop i'm using formatting in code seen below...
<div class="three columns"> <div class="product_container no_border"> <div class="product"> <a href="product_page.html"><img src="<?php echo $this->getskinurl('images/products/place_holder.jpg'); ?>" alt=" "></a> </div> <div class="product_title"> <a href="product_page.html">240 serving package</a> </div> <div class="price_hp">$454.99</div> <div class="free_shipping"> <div class="fs"></div> free shipping package </div> <div class="shop_btn"> <a href="#">add cart</a> </div> </div> </div>
i don't know php use though grab 4 products category , randomize order. may have guidance please?
thanks!
use following code in phtml file randomize products..
$categoryid = 15; $category = new mage_catalog_model_category(); $category->load($categoryid); $products = $category->getproductcollection(); $products->addattributetoselect('*'); $products->getselect()->order('rand()'); $products->getselect()->limit(4); foreach($products $prod) { echo $prod->getname() ."<br>"; $img=$prod->getsmallimageurl(); echo "<img src='$img'>" ."<br>"; }
Comments
Post a Comment