Skip Navigation

[Resolved] Getting a list of images, in 2 sizes, from repeating field

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 support ticket is created 9 years 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by Shawn 9 years ago.

Assisted by: Luo Yang.

Author
Posts
#293394

I have a repeating image field. I'd like to output those images in my theme template as thumbnails with links to their full-size versions. I've seen a couple of posts about this in this forum but the answers didn't work... https://toolset.com/forums/topic/repeating-images-for-slider-in-php-not-shortcodes/

Using luoy's code from the above post, I am able to output the images, but it doesn't return the thumbnail versions. I'm also getting a PHP notice "Notice: Trying to get property of non-object".

Is this not possible with Types? I have Views as well, but I couldn't figure out how to do it with that either.

#293621

Could you post the PHP codes you are using, I need test and debug in my localhost, thanks

#293700

Here's the relevant code:

$sp_slug = 'site_plan_tab_images';
$sp_html = '';
$site_plan_images = get_post_meta( $the_id, 'wpcf-'.$sp_slug );
$site_plan_images = array_filter( $site_plan_images );
$sp_html = '';
if ( !empty( $site_plan_images ) ) :
	foreach( $site_plan_images as $k=>$v ) {
		$field = wpcf_fields_get_field_by_slug( $sp_slug );
		$params = array( "alt" => "", "title" => "", "size" => "thumbnail", "proportional" => "true", "url" => "true" );
		$params['field_value'] = $v;
		$thumbnail = types_render_field_single( $field, $params, null, '', $k );
		$params['size'] = 'full';
		$fullsize = types_render_field_single( $field, $params, null, '', $k );
		$sp_html .= '<a href="' . $fullsize . '"><img src="' . $thumbnail . '"></a>';
	}
	$tabs_content[] = $sp_html;
endif;

The output I'm getting from the above is this:

<a href="<em><u>hidden link</u></em>"><img src="<em><u>hidden link</u></em>"></a>

Along with the php notice I mentioned in the original post.

Thanks in advance!

#293899

Please try modify the codes as below:

$sp_slug = 'site_plan_tab_images';
	$sp_html = '';
	$site_plan_images = get_post_meta( $the_id, 'wpcf-' . $sp_slug );
	$site_plan_images = array_filter( $site_plan_images );
	$sp_html = '';
	if ( !empty( $site_plan_images ) ) :
		$field = wpcf_fields_get_field_by_slug( $sp_slug );
		foreach( $site_plan_images as $k=>$v ) {
			$params = array( "size" => "thumbnail", "proportional" => "false", "url" => "true" );
			$params['field_value'] = $v;
			$thumbnail = types_render_field_single( $field, $params, null, '', $k );
			$params['size'] = 'full';
			$fullsize = types_render_field_single( $field, $params, null, '', $k );
			$sp_html .= '<a href="' . $fullsize . '"><img src="' . $thumbnail . '"></a>';
		}
    $tabs_content[] = $sp_html;
	endif;

Please replace "site_plan_tab_images" with your custom image field slug, make sure the var $the_id works correct.

#294065

That worked! So, moving

$field = wpcf_fields_get_field_by_slug( $sp_slug );

outside of the foreach loop seems to be what fixed it. Can you explain?

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.