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 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 vor 6 Jahren, 6 Monaten.
Assistiert von: Christian Cox.