Skip Navigation

[Resolved] Need to display a file's title and cover image

This support ticket is created 2 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/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by Waqar 2 years, 3 months ago.

Assisted by: Waqar.

Author
Posts
#2470807
Example01.jpg

Tell us what you are trying to do?
I'm trying to create an easy to use method for a client to load a pdf document into the media library, add a title/cover image, and see the title/cover image as the link on the front end in the page.

I updated the Child: functions.php with the following code that I found:

/**
* Function to get the title from the pdf document
*/

add_shortcode( 'my_file_name', 'my_file_name_func'); // Actually activate the shortcode

function my_file_name_pdf_func($atts) {
global $post; // So we can get the post meta later on
$res = ''; // Setting up a variable to hold the links so we can return it later
$types = $atts['field'];
if ($types) { // if the types_field argument was provided

//define ShortCode attr prefix
$types = "wpcf-$types";

$urls = get_post_meta($post->ID,$types); // let's get the (potentially multiple) values
if(empty($urls[0])){
return;
}
$arr = array();
foreach ($urls as $fileurl) { // Let's iterate for each of the multiple values

$id = pippin_get_image_id($fileurl);
$title = get_the_title($id);
$arr[] = '' . $title . ''; // Create whatever HTML and store it in the $content variable
}
$res = implode(' | ', $arr);
}
return $res; // Return the content as the shortcode value
}

But then I don't know how to integrate the shortcode value in the view that I'm working on. I added it under "Field Settings" > Optput mode > File link tile "my_file_name" but it is not working 🙁 (Probably I'm doing something really wrong - but I don't know how to call this shortcode under this view) - Image attached.

Is there any documentation that you are following?
Yes, the one from here: https://toolset.com/forums/topic/displaying-file-title-with-a-link-for-custom-field-for-manuals-etc/

Is there a similar example that we can see?
Yes, here is the link:
hidden link

What is the link to your site?
hidden link

#2471097

Hi,

Thank you for contacting us and I'd be happy to assist.

Based on what you've shared, the code from the other support ticket is different from your requirement.

Can you please share temporary admin login details, so that I can see how the relevant fields are set up?

I'll be in a better position to suggest the next steps, accordingly.

Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.

regards,
Waqar

#2473291

Thank you for sharing the access details.

During troubleshooting, I noticed that the custom shortcode was already registered on the website through the code snippet named "filename-attachments", at WP Admin -> Toolset -> Settings -> Custom Code.

I included a "Fields and Text" block in the view and added this custom shortcode, which worked as expected:


[my_file_name types_field="press-release"]

Screenshot back end: hidden link
Screenshot front end: hidden link

Similarly, you can use this custom shortcode to display the title and link of the files from the other fields, too.