jcadima
4/22/2016 - 6:34 PM

Custom Featured products

Custom Featured products

<?php

/*  
create this on  /app/design/fronend/cendo/ma_cendo1/template/featuredcustom/
Note we created directory featured custom , thats where featuredcustom.phtml (this file will go)
*/

$counter = 1;
$products = Mage::getModel('catalog/category')->load(55); //put your category id here
       $productslist = $products->getProductCollection()->addAttributeToSelect('*');
       foreach($productslist as $product)
       {
	       if ($counter > 2 ) break;  // limit 2 products only
	       if ($counter > 1) { 
		       $position = 'text-right' ;
		   }
		   else {  
			   $position = 'text-left'  ;
		   }

	    echo "<div class='col-md-6   container-$position'>" ;
	    	echo "<div class='featimg $position'>"  . '<img src="' . $product->getImageUrl() . '"></div>' ;  
	    	
	    	echo "<div class='featname $position'>" .$product->getName() . '</div>' ;

	    	//echo 'Product Price : ' . $product->getPrice() . '<br/>';
	    	
	    	$shortdesc = substr($product->getDescription(), 0, 100 ) . ' ...' ;
	    	
	    	echo "<div class='$position'> " . $shortdesc . '</div>';
	    	
	    	echo "<div class='$position'>" .   '<a class="featbluebtn" href="' . $product->getProductUrl() . '">LEARN MORE</a></div>';	    	
	    	
	    echo '</div>';   
	  
        $counter++;
       }
       


/*
Then use this template on a CMS page:
*/

<div class="featured_products text-center">

{{block type="core/template" template="featuredcustom/featuredcustom.phtml"}}

</div>