Magento Coding Solutions

Get Product by Category Id

<style> .prodectDiv{background: none repeat scroll 0 0 #F2F2F2; float: left; height: 140px;  margin: 5px; padding: 2px;  text-align: center;  width: 140px;}
.pname{pading-top:1px; text-align:center;}
.pname a{color: #fff;}
</style>

<div style="float:left;width:100%;" >
<?php
//echo "<pre>";
$categoryid = 40;
$category = new Mage_Catalog_Model_Category();
$category->load($categoryid);
$collection = $category->getProductCollection();
$collection->addAttributeToSelect('*');
$collection->getSelect()->order(new Zend_Db_Expr('RAND()'));
//echo "Design".count($collection);
$i=1;
foreach($collection as $_product){?>
<div class="prodectDiv" >
<a href="<?php echo $_product->getProductUrl() ?>"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(120); ?>" width="120" height="120" alt="" /></a>
<p class="pname" >
<a href="<?php echo $_product->getProductUrl(); ?>"><?php echo substr($_product->getName(),0,20); ?></a>
</p>
</div>
<?php


$i++;
} ?>
</div>

No comments:

Post a Comment