Display magento products by category ID

$categoryIds = array(18);//category id

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

Get detail of products

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

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


<div class="product-name">

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


<div class="product-price">

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


<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 ?>


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


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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s