0

I have this code to display the product image in the description area of a product

<?php
    $_product = $this->getProduct();
    $_helper = $this->helper('catalog/output');
?>
<?php if ($_product->getImage() != 'no_selection' && $_product->getImage()): ?>
<p class="in-content-image">
    <?php
        $_img = '<img class="in-prod-content" itemprop="image" id="image" id="image" src="'.$this->helper('catalog/image')->init($_product, 'image').'" alt="'.$this->htmlEscape($this->getImageLabel()).'" title="'.$this->htmlEscape($this->getImageLabel()).'" />';
        echo $_helper->productAttribute($_product, $_img, 'image');
    ?>

What i want to do is to create an if statement that show the second image of the product as the first option, and if there is no second image in that product it should show the first default image, anyone might know how i can do that?

0

Try this:

<?php if ($_product->getImage() != 'no_selection' && $_product->getImage()): ?>
  <p class="in-content-image"> 
    <?php if (count($_product->getGalleryImages()) > 0): ?>
         <?php foreach ($this->getGalleryImages() as $_image): ?>
            <img class="in-prod-content" itemprop="image" id="image" id="image" src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(56); ?>" width="56" height="56" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" />
            <?php break;?>
         <?php endforeach; ?>
    <?php else:?>
        <?php $_img = '<img class="in-prod-content" itemprop="image" id="image" id="image" src="'.$this->helper('catalog/image')->init($_product, 'image').'" alt="'.$this->htmlEscape($this->getImageLabel()).'" title="'.$this->htmlEscape($this->getImageLabel()).'" />';
        echo $_helper->productAttribute($_product, $_img, 'image');
?>
    <?php endif; ?>

</p>
<?php endif; ?>
  • Hi abdul, thanks for the answer, but seems that it does not work for me, it gets the same result of showing the first image. – Man Shlomo Dec 10 '15 at 10:02

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.