Magento Forum

Pulling product ID on product page
 
Tropical
Jr. Member
 
Total Posts:  16
Joined:  2007-12-30
 

Is there a variable I can use to pull the product id (or some other unique identifier) on the product page? I want to display an image depending on what product it is (1 through 4) so I was going to do something like <img src="images/<? $id ?>” alt="image" /> but I’m not what var to use.

Thanks for any help

 
Magento Community Magento Community
Magento Community
Magento Community
 
dan_w
Sr. Member
 
Total Posts:  290
Joined:  2008-01-04
 

Hey Tropical,
Try using <img src="images/<?=$_product->getId()?>" alt=""/>. Or, you could change it to use the sku with getSku.

Dan

Edit: I thought that I should mention that you’d obviously need to declare the image type after the product id. So you it should probably look like:
<img src="images/<?=$_product->getId()?>.jpg" alt=""/> or whatever your image extension is.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Tropical
Jr. Member
 
Total Posts:  16
Joined:  2007-12-30
 

That works perfectly, thanks a lot smile

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top