I want to display only the products that use image, not placeholder:

<?php $_productCollection = Mage::getResourceModel('reports/product_collection')
                           ->setOrder('created_at', 'desc')
                           ->setPage(1, 10); ?>

                    <?php foreach($_productCollection as $_product) : ?>
                        <li class="item">
                            <a href="<?php echo $_product->getProductUrl() ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(220, 150); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
                            <h2 class="product-name"><a href="<?php echo $_product->getProductUrl(); ?>"><?php echo $_product->getName(); ?></a></h2>

                <?php endforeach; ?>

1 Answer 1


Try this code :

if ($_product->getSmallImage()!='no_selection' ) { 
// product with image
  • I have this code too, can you tell me where I can put the if? if I put this after foreach will not display anything?.
    – Robert
    Jan 28, 2017 at 11:55
  • sure , you do put within foreach. If it will not display anything then please check 'smallimage' is selected or not for the products. Jan 28, 2017 at 13:36
  • Please add that info to your answer
    – 7ochem
    Jan 28, 2017 at 21:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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