Skip Navigation

[Resolved] Repeatable PDF images broken v2

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

Problem:

When the field is repeatable it works as i want it to - show image and on click open related PDF file, but when the field has only one file it shows and image and on click it opens the image on a tab which i dont want - I need the PDF file.

How to make this work the same for one file?

Solution:

It is a custom PHP codes problem, see details here:

https://toolset.com/forums/topic/repeatable-pdf-images-broken-v2/#post-1291597

Relevant Documentation:

This support ticket is created 5 years, 6 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 stuartm-2 5 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#1291053

Hello im opening a new thread because i didnt receive any response here.

https://toolset.com/forums/topic/repeatable-pdf-images-broken/page/2/

It is marked resolved but i found a an issue.

"" Hello Shane,
Thank you for your help with the code above some time ago.
But i just noticed an issue as you can see in the pictures. When the field is repeatable it works as i want it to - show image and on click open related PDF file, but when the field has only one file it shows and image and on click it opens the image on a tab which i dont want - i need the PDF file.
How to make this work the same for one file?
Thank you. ""

#1291361

Hello,

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 website, I need to test and debug it in a live website, thanks

#1291547

Thanks for the details, I can log into your website.

Please provide the problem post URL:
Where and how can I see the problem as you mentioned above:
but when the field has only one file it shows and image and on click it opens the image on a tab which i dont want

#1291549
file.PNG

hidden link
Here is the link to a post as an example. At the bottom right there is already a file as shown in the picture.
So clicking one file links to the image file which is the issue, but if you edit the post and add more PDF files { repeating fields} works normally displays all images and links to the PDF files as i want it.

Thank you

#1291597

Thanks for the details, I have done below modification in your website:
Edit your theme file "functions.php", add below codes in line 197~199:

	if(count($img_arr) == 1){ // only one pdf file
		return $output .= "<a href='".types_render_field( "files-for-approval", array('output'=> 'raw'))."'><img src='".$img_arr[0]."'/></a>";
	}

Please test again, check if the problem is fixed, thanks

#1291791

Thank you Luo for changing the code it works properly now. You have been very helpful.
Have a nice day!