Skip Navigation

[Resolved] Display a media attachment page's image

This support ticket is created 4 years, 11 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 2 replies, has 2 voices.

Last updated by Peter 4 years, 10 months ago.

Assisted by: Luo Yang.

Author
Posts
#1441507

I am trying to:
Display the image from a media attachment page.

Link to a page where the issue can be seen: Issue is on private pages.

I expected to see:
Prior to update to Views 3.0.1 and WP 5.3, [wpv-post-body view_template="None" item="123"] would show the attachment page's image and Description (if any).

Instead, I got:
Only the description appears now.
I understand from the changelog that this may have been an intended change at Views 2.9.4, but can't figure out how to extract the image from the attachment ID now. Could you advise please?

#1442109

Hello,

I assume we are talking about a media attachment, ID is 123.

I have tried it in my localhost, with below steps:
1) WordPress 3.0 (https://wordpress.org/download/releases/) + Toolset Views plugin 3.0.1,
Test the shortcode you mentioned above:
[wpv-post-body view_template="None" item="123"]
I can see only the image description,

2) WordPress 3.0 (https://wordpress.org/download/releases/) + Toolset Views plugin 2.9.4
Same as above, I can see only the image description,

In the latest version of Views plugin, you can try these:
1) add below PHP codes into your theme file functions.php:

add_shortcode('attach-url', function($atts, $content){
	return wp_get_attachment_url($atts['id']);
});

2) Use below shortcode to get attachment info, like this:

URL:
[attach-url id=123]
Alt:
[wpv-post-field name="_wp_attachment_image_alt" item=123]
Title:
[wpv-post-title item=123]
#1442639

Thanks Luo, that's helped me in the right direction.