Skip Navigation

[Resolved] Display Custom Image Field (repeating) with the Types API

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.

This thread is resolved. Here is a description of the problem and solution.

Problem:
How can I display a Custom Image Field that is repeating, with the Types API?

Solution:
You can use the Types API to do that.
Dysplaying the Image Field is not much different then other Fields, and it does not really matter if it is repeating, as long you do not want to customize the outoput for EACH Image.
This is a sample code to display Images with Types API:

echo types_render_field('image', array("width" => "300", "height" => "200"))

Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/functions/#image

This support ticket is created 7 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 5 replies, has 2 voices.

Last updated by daveM 7 years, 8 months ago.

Assisted by: Beda.

Author
Posts
#426257

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?

#426392

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

#426739

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

output=html

would wrap it in

<img>

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

#426742

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?

#426949

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.

#427078

Ah, the issue was I forgot the "echo" in the code.

Thanks for your help!

The forum ‘Types Community Support’ is closed to new topics and replies.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.