Magento 1.9 – How to Check if Products Have Images

imagemagento-1.9PHPproducts

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

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

                    <ul>
                    <?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>
                        </li>

                <?php endforeach; ?>
                </ul>

Best Answer

Try this code :

if ($_product->getSmallImage()!='no_selection' ) { 
// product with image
} 
Related Topic