Skip Navigation

[Resolved] Repeating images for slider in php, not shortcodes

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 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.

This topic contains 11 replies, has 6 voices.

Last updated by Shawn 5 years, 5 months ago.

Assigned support staff: Luo Yang.

Author
Posts
#138935

Hi.
How would I repeat images from a field and wrap them in custom tags. I want to use a basic jquery slider and I just need to echo out each image url but put my own htlm before and after each one.
Many thanks

#139121

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Hi sams-3,

I assume your repeat image field is created by Types, using slug "my-images",

Please try this:

$slug =  'my-images';
$size = 'thumbnail';
$meta = 'url';
global $wpcf;
	$my_field = new WPCF_Repeater();
	$my_field->set(get_the_ID(), wpcf_admin_fields_get_field($slug));
	$get_meta = $my_field->_get_meta();
	$arr = array();
	if(isset($get_meta['custom_order']))
	{
		$arr = $get_meta['custom_order'];
	}
	foreach($arr as $k=>$v)
    {
      
        $field = wpcf_fields_get_field_by_slug( $slug );
        $params = array("alt" => "", "title" => "", "width" => "80", "height" => "80", "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);
        $res .= '<a href="' . $fullsize . '"><img src="' . $thumbnail . '"></a>';
    }
	echo $res;

it will return such a html:

<a href="' . $fullsize1 . '"><img src="' . $thumbnail1 . '"></a>
<a href="' . $fullsize2 . '"><img src="' . $thumbnail2 . '"></a>
<a href="' . $fullsize3 . '"><img src="' . $thumbnail3 . '"></a>
#139172

Thank you so much. Even though that is a lot of code his works perfectly.
Kudos for you sir

#159323

Well, your code works, but it doesn't show thumbnails as expected. Can someone verify that thumbs are in fact showing?

#159324

Sorry, should have clarified, this code DOES show an image, but only the full size, instead of a thumb. Link to full size works as expected though.

#242866

Yes, I have the same issue. Shows my images just fine, but only shows the full size, even when I specify "thumbnail".. Is there a fix for this?

#242868

(also, I am using this plugin, https://wordpress.org/plugins/wpro/), which posts media to S3 without writing to the local server. I am testing this on my localhost

Essentially I want

<a href="LINK TO FULL IMG"><img src="THUMBNAIL" SIZE TO BE MY THUMBNAIL SETTING></a>
#271117

Where are you supposed to place this code? When I add this to a Custom View it does nothing except except place a few line breaks and output some of the code onto the page. I'm guessing this has to go somewhere else besides your View template?

#271161

You would place this code in a template file, such as header.php or page.php.

It is for hard coding into your theme, rather than using in a page content area.

#293388

I'm having the same issue as mayurJ, Types is not outputting the thumbnails, only full size images. Is this not possible with Types? I'm also getting this php notice:

Notice: Trying to get property of non-object in [...]/plugins/types/embedded/views/image.php on line 815

#293686

Shawn, are you running this on your local machine or a development URL? I have had some issues in the past with using this when developing on the server address, like hidden link, rather than the domain

#293702

@sams-3:
Both. I have a localhost site and a staging site online. The staging site has errors turned off so you don't see the notice but the output in the html is the same.

I started another thread here: https://toolset.com/forums/topic/getting-a-list-of-images-in-2-sizes-from-repeating-field/#post-293700

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