I want to show some specific product on product listing page :

like product_collection.phtml

there is a code that grab the collection


It show all products in particular category but I want to show few product by there ids may be array of product ids like


how can I do that add filter or any other way ?..

i tried below code but it is not working . code of product_collection.phtml:

/* added code for filter start */
        $productIds = array(1,3,2);
        $_productCollection=$this->getLoadedProductCollection()->addAttributeToFilter('entity_id', array('in' => $productIds));

/* added code for filter ends */
/*order code

        $_helper = $this->helper('catalog/output');

    <?php $_collectionSize = $_productCollection->count() ?>
    <?php $_columnCount = !empty($cols)?$cols:$this->getColumnCount(); ?>  
    <div class="category-products">
        <?php echo $this->getToolbarHtml(); ?>

        <div class="products-block" id="products-grid">
        <?php $i=0; foreach ($_productCollection as $_product): ?>
            <?php if ($i++%$_columnCount==0): ?>
            <div class="row products-grid">
            <?php endif ?>

                    <?php echo $_product->getName().'<br>';?>

                <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
                <?php endif ?>
                <?php endforeach ?>
                <script type="text/javascript">decorateGeneric($$('div.products-row'), ['odd','even','first','last'])</script>
        <div class="toolbar-bottom">
            <?php echo $this->getToolbarHtml() ?>

2 Answers 2


Instead of using getLoadedProductCollection() method, you can create your own custom collection. It should somewhat looks like this.

//use product ids that you need to show in this array
$productIds = array(11, 12, 1, 4);

//loads collection based on Ids
$collection = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToFilter('entity_id', array('in' => $productIds));

//loop through custom collection in order to grab data
foreach ($collection as $item) {
  • giving downvote is ok. May I know what is the reason ? Oct 13, 2014 at 5:44
  • Same answer just look and fill diff this is not a good way to keep both answer same
    – Keyul Shah
    Oct 13, 2014 at 5:45
  • I have not down vote your answer.
    – Keyul Shah
    Oct 13, 2014 at 5:49
  • @KeyulShah:that +1 from my side for put a good answer Oct 13, 2014 at 5:55

Hello Try the Below code.

$productIds = array(1,3,2);
    $products = Mage::getModel('catalog/product')->getCollection()
                ->addAttributeToFilter('entity_id', array('in' => $productIds));

Or Try One of them.

$products =$this->getLoadedProductCollection();
$products ->addAttributeToFilter('entity_id', array('in' => $productIds));


    foreach($products as $product)
        echo $product->getEntityId();
        echo $product->getSku();

In collection you have to add filter using addAttributeToFilter and pass the $productIds array.

  • please update the error
    – Keyul Shah
    Oct 13, 2014 at 5:58
  • what is actual error so we can help
    – Keyul Shah
    Oct 13, 2014 at 5:59
  • i wrote below code $productIds = array(1,3,2); $_productCollection=$this->getLoadedProductCollection()->addAttributeToFilter('entity_id', array('in' => $productIds)); $_helper = $this->helper('catalog/output'); it shows all products not filtered result
    – mcoder
    Oct 13, 2014 at 6:02
  • does product id same as entity id?
    – Keyul Shah
    Oct 13, 2014 at 6:08
  • yeah , in need to filter via product ids, see my updated quesion
    – mcoder
    Oct 13, 2014 at 6:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.