Display magento products by category ID

<?php
$categoryIds = array(18);//category id

$collection = Mage::getModel('catalog/product')
->getCollection()
->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
->addAttributeToSelect('*')
->addAttributeToFilter('category_id', array('in' => $categoryIds))
$_collectionSize = $collection->count()
?>

Get detail of products

<ul>
<?php $i=0; foreach ($collection as $_product):  ?>
<?php $i++;?>
<?php if($i!=4){ // for maximum 3 product ?>
<li>
<div class="product-image">

<img src="<?php echo Mage::helper('catalog/image')->init($_product, 'small_image')->resize(); ?>" />

</div>

<div class="product-name">

<a href="<?php echo $_product->getProductUrl();?>"><?php echo $_product->getName(); ?></a>

</div>

<div class="product-price">

<?php echo Mage::helper('core')->currency($_product->getPrice(),true,false);?>

</div>

<div class="product-Short Description">

<?php echo    Mage::helper('core/string')->truncate($product->getShortDescription(), $length = 50, $etc = '...', $remainder = '', $breakWords = true); // word limit for short description ?>
</div>

</li>

<?php } else{break;}?>
<?php endforeach ?>

</ul>
Advertisements

2 thoughts on “Display magento products by category ID

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s