Skip Navigation

[Resolved] Get a thumb version of an image based on its ID

This support ticket is created 5 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

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)

This topic contains 5 replies, has 2 voices.

Last updated by Luo Yang 5 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#1289985

Hi,
I have this code

<img class="" src="[wpv-post-field name='pyre_page_title_bar_bg']"/>

which shows an image within a <img> tag.
But this shows the image in its full resolution, and I'd like to get a smaller one.
In order to do this, I noticed I also have the image id with this code

[wpv-post-field name='pyre_page_title_bar_bg_id']

But now I wonder how to get the small version of the image based on the image ID.
How would this be achievable ?
Thank you.

#1290187

Hello,

How do you setup/create the custom field "pyre_page_title_bar_bg"?

If it is a custom image field created with Types plugin, you can use Types shortcode to display the image in specific size, see our document:
https://toolset.com/documentation/customizing-sites-using-php/functions/#image
Attribute "size":
custom image size | 'full' | 'large' | 'medium' | 'thumbnail'
width and height will be ignored if size is set.

url:
'false'(default) | 'true'
true=output the url of the image instead of the html img tag.

Works with the size attribute to output the url of the re-sized image

#1290425

Thank you.
The custom field is added by the theme Avada, in the page Avada options.
It stores the URL of the full image, and the ID of the image.
Based on those, I would need to find the URL of the small version of the image.
Thank you

#1291331

There isn't such a built-in feature within Toolset plugin, I suggest you check it with Avada support:
hidden link

And you can consider custom codes too, for example:
https://toolset.com/forums/topic/get-id-of-attachment/#post-291761

#1291709

Hello and thank you,
I found this function https://developer.wordpress.org/reference/functions/wp_get_attachment_image/
And tried to build it that way :

function recup_attachment($atts) {
	$image_id = $atts["imgid"];
	wp_get_attachment_image( $image_id, '400');
}
add_shortcode("le_thumb", "recup_attachment");

With shortcode

[le_thumb imgid="[wpv-post-field name='pyre_page_title_bar_bg_id']"]

but with no result. Nothing appears in frontend, and there is no errors in log files neither...
Thank you.

#1292239

Since it is a custom PHP codes problem, please provide a test site with the same problem, also point out the problem page URL and where I can edit your PHP codes, I need to test and debug it in a live website, thanks