0

I am learning Magento. I am trying to list out my product images.

Firstly I tried with a single product and it worked:

<?php
$productModel = Mage::getModel('catalog/product');
$product_1 = $productModel->load(1);
?>
<div><a href="<?php echo $product_1->getProductUrl();?>"><img src="<?php echo $product_1->getImageUrl()?>" /></a></div>

Then, I create a collection to show a list of pictures, but it showed all Magento logos, not product pictures. (I checked base, small and thumbnail image in admin already)

<?php
  $product_collection = Mage::getModel('catalog/product')->getCollection()->setOrder('name', 'asc'); 
?>
  <div class="tai-slider2">
<?php
  foreach($product_collection as $_product)
       {
?>
  <div><a href="<?php echo $_product->getProductUrl();?>"><img src="<?php echo $_product->getImageUrl()?>" /></a></div>
<?php
        }  
?>

Please help! Thank you!

2 Answers 2

1

Maybe try adding image attribute to your collection will do the trick

$product_collection = Mage::getModel('catalog/product')
                            ->getCollection()
                            ->addAttributeToSelect('image')
                            ->setOrder('name', 'asc'); 

<div class="tai-slider2">
    <?php foreach ($product_collection as $_product) { ?>
        <div>
            <a href="<?php echo $_product->getProductUrl();?>">
                <img src="<?php echo $_product->getImageUrl()?>" />
            </a>
        </div>
    <?php } ?>
</div>
0

Try with this way

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

Instead of 'image' you can also use 'small_image' or 'thumbnail'.

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.