Magento – How to get products list by category ID

categorycollection;magento-1product-collectionproducts

How can I get a products list by category ID? I need to display them with products name or ID.

My code so far:

$productCollection = Mage::getModel('catalog/product')->load($currentctid)
                    ->getCollection() 
                    ->addAttributeToSelect('name')
                    ->addAttributeToFilter('status', array('eq' => 1))
                    ->joinTable('pdp/productstatus', 'product_id=entity_id', array('*'));

Best Answer

This should do the trick. It retrieves the active category. If that is not set it gets the first category the product is assigned to. The collection holds all products for that category

$category = Mage::registry('current_category');
if (empty($category)) {
   $product = Mage::registry('current_product');
   $categoryId = reset($product->getCategoryIds());
   $category = Mage::getModel('catalog/category')->load($categoryId);
}

$collection = Mage::getResourceModel('catalog/product_collection')
        ->setStoreId(Mage::app()->getStore()->getId())
        ->addCategoryFilter($category);