Skip Navigation

[Résolu] Display repeating list of pdf files with name (and downloadable link)

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem: I have a repeating file field that holds PDF files. I would like to loop over the list of files and display an unordered list that shows the file name as a downloadable link.

Solution: You can use the wpv-for-each shortcode to loop over each instance in a repeating field, but there's no built-in way to extract the file name from the custom field value. The custom field value will include the full URL of the file. You can add this custom shortcode to your child theme's functions.php file:

add_shortcode( 'my_file_name', 'my_file_name_func');
function my_file_name_func($atts)
{
  $urls = $atts['file_url'];
  $fileparts = explode('/', $urls);
  return end($fileparts);
}

Then in the wpv-for-each loop, you can use it like this to extract the file name and construct download links:

<ul>
  [wpv-for-each field="wpcf-upload-file"]
<li><a href="[types field='upload-file'][/types]">[my_file_name file_url="[types field='upload-file'][/types]"][/my_file_name]</a></li>
[/wpv-for-each]
</ul>

Relevant Documentation:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-for-each

This support ticket is created Il y a 5 années et 10 mois. 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Marqué : 

This topic contains 3 réponses, has 2 voix.

Last updated by Athlone Il y a 5 années et 10 mois.

Assisted by: Christian Cox.

Auteur
Publications
#880703
screenshot-toolset-views - 13 May 2018.jpeg

Tell us what you are trying to do?
I've created a CPT with some custom fields. One field is a repeating field of PDF files.

What I want to do is output the list of files in an UL displaying the file name (that is a link to download the file or open it in a new window).

Environment: Beaver Builder with Beaver Themer In Beaver Builder's Text Editor I'm using the following:

  • [types field='general-arrangement-drawings' link='true' separator='
  • '][/types]

It's displaying the file in a UL as a link, but I want to display the file name, not the full path.

I've gone through the documentation and it seems like there is not a solution, can you assist?

#880705

Hi there, yes I do still need help. Thanks...

#881380

Hi, you can use the wpv-for-each shortcode to loop over each instance in a repeating field, but there's no built-in way to extract the file name from the custom field value. The custom field value will include the full URL of the file. You can add this custom shortcode to your child theme's functions.php file:

add_shortcode( 'my_file_name', 'my_file_name_func');
function my_file_name_func($atts)
{
  $urls = $atts['file_url'];
  $fileparts = explode('/', $urls);
  return end($fileparts);
}

Then in the wpv-for-each loop, you can use it like this to extract the file name and construct download links:

<ul>
  [wpv-for-each field="wpcf-upload-file"]
<li><a href="[types field='upload-file'][/types]">[my_file_name file_url="[types field='upload-file'][/types]"][/my_file_name]</a></li>
[/wpv-for-each]
</ul>

https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-for-each

#882749

Hi Christian

Thanks for the reply and solution, it works just fine. I see with repeating fields "wpv-for-each" must be used, that's what tripped me up.

Warmest regards,

Athlone

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.