I am trying to get URL of image of last image.

<?php echo $this->helper('Magento\Catalog\Helper\Image')->init($block->getProductForThumbnail(), 'cart_page_product_thumbnail')
            ->resize(165, 165)->getUrl(); ?>

This code gives me url of first image, How can i get url for the last image.


You can't using the above logic.

Remember that the default image roles define a single product image as Base, Small, Thumbnail.

I recommend that you add another custom image role


Set the last image as this custom role. Then update your template logic where required to get image based on this custom role instead.


If response to your comment

See here how they've put together block logic and render small image. What defines small image is because of the dimensions.


I still think you are going to have to create and use a custom image role.

| improve this answer | |
  • Xigne , How can i get small_image in magento 2, the image which i want to show is small_image – summu Jun 2 '19 at 14:03

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.