How to make custom field images clickable
-
I have a product page where underneath the featured image I have added some thumbnails using a custom field. I want to be able to click on the thumbnails and they open up in a new window. I used the types plugin to create the field. I don’t want to use two separate fields (one for the image, the other for the link) because I am trying to keep it simple for my client. I started with this chunk of code
<ul id="product-images"> <li> <img src='<?php echo types_render_field("product-image", array("raw"=>"true","separator"=>"'></li><li><img src='")); ?>'> </li> </ul>
which would display all of the images that I added with the custom field but got confusing when I added the link around the images with the separator and felt that probably wasn’t the best route.
Right now I have<ul id="product-images"> <li> <a href="<?php echo get_post_meta( get_the_ID(), 'wpcf-product-image', true ); ?>" target="_blank"><img src="<?php echo get_post_meta( get_the_ID(), 'wpcf-product-image', true ); ?>" /></a> </li> </ul>
which is showing one image but not the others. I know that using ‘true’ only shows the first value of the custom field but when I change it to ‘false’ it prints out the word array. I’m not sure if there is away to change this chunk of code to display all values of the custom field or if I should be using something else.
Could a foreach loop be used?Here’s the link to my product page
https://test.arccrafts.com.php53-19.ord1-1.websitetestlink.com/products/cherry-wood-sheet-8-5×11-adhesive-backing-bulk/Any help will be greatly appreciated. I have been researching for about week on how to do this.
- The topic ‘How to make custom field images clickable’ is closed to new replies.