I have a custom image field that allows multiple instances (repeating).
I'm trying to display ALL values of this repeating field within my single-{custom-post-type}.php template file. I need to display the values as <img> tags with the image urls in the src—no separators needed.
I'm following the direction of the documentation, here: https://toolset.com/documentation/customizing-sites-using-php/functions/#image, but I can't seem to get any of the images to show.
I've stripped the code down to this:
types_render_field('gallery-images');
But nothing is showing on my page or in the page source. No <img> tags, no image urls, nothing.
Any ideas?
When you display repeating Images you need a separtor.
Specially when you want to create a list or so of HTML tags.
In ShortCode terms (using ShortCodes) thi is done as follows:
1. You insert the ShortCode
2. You wrapt it in the opening and closing HTML Tag
3. YOu separate it by the closing and opening tag.
This gives you this output:
<img>[types field='image' size='full' align='none' separator='</img><img>'][/types]</img>
Do you see the logic here?
It will open a HTML tag, close it in the separator, re-open it in the separator and then close it finally at the end.
The same can be done with other HTML tags.
https://toolset.com/documentation/user-guides/repeating-fields/
The same should apply for the PHP.
Do you already know Views and Layouts?
Those 2 Plugins would remove the need for PHP on most cases
Hi Beda,
Thanks for the reply. I'm not using shortcodes. Does the php template tag also require hard-coding the opening and closing tags? I thought
would wrap it in
tags.
How would I simply get the image url in the src of an img tag using the php below?
<?php types_render_field('gallery-images', ''); ?>
Thanks,
Dave
The "edit" link on my previous post isn't working, so I'm posting again.
All I want to output is this:
<img src="the/url/to/my/first/image.jpg" /><img src="the/url/to/my/second/image.jpg" /><img src="the/url/to/my/third/image.jpg" />
...and so on. No separators. Just the image tag with the image url. Is that possible?
If you do a var_dump() of types_render_field( 'image', array()) you will see, it already holds all HTML you need, and it is not a single value.
If you echo types_render_field( 'image', array()) you will get all those images - in the original size, with HTML img src tags.
If you do:
echo types_render_field('image', array("width" => "300", "height" => "200"))?>
you will get them in the exact mentioned sizes.
This works great locally.
Please can you test my code?
If this does not work on your end, it must be a issue with some plugin/theme or the server.
Ah, the issue was I forgot the "echo" in the code.
Thanks for your help!