Skip Navigation

[Gelöst] Display repeating list of pdf files with name (and downloadable link)

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

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 vor 6 Jahren, 6 Monaten. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

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)

Dieses Thema enthält 3 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Athlone vor 6 Jahren, 6 Monaten.

Assistiert von: Christian Cox.

Author
Artikel
#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