What is the link to your site? hidden link
An example of the problem: hidden link (see attachment)
People can upload files through a repeating field of the type: file.
The output where you can see what was up[loaded looks like this:
[wpv-conditional if="(NOT(empty($(wpcf-bestand))))"][types field='bestand' link='true' title='Klik hier voor het bestand' separator=', '][/types][/wpv-conditional]
In this situation every file gets the title: Klik hier voor het bestand
How can I give meaningful titles to the uploaded files and output them in a column?
I have seen this: https://toolset.com/forums/topic/display-file-name-of-uploaded-file/
But it is too complicated. Can you help me on my way?
Regards,
Jos
Hi, there isn't an easy way to associate a title with an existing repeating file field, because it's only designed to store one piece of information: the file URL. A different approach with Repeatable Field Groups, or RFGs, is more flexible. You can store both a file title and a file URL, using two separate fields. Then use a View to loop over each RFG and display the title as a link to the URL.
The RFG approach doesn't require any custom PHP code, but it may require a significant amount of work in wp-admin because it's not compatible with a repeating custom field. In other words, you would have to manually update each post that already contains a repeating file field. Then the conditional code you're currently using to display those repeating images must be replaced by a View of RFGs with a post relationship filter. Finally, any Forms you use to create this content on the front-end of the site must be updated and new RFG Forms must be added.
If that sounds like something you would like to explore, we have more information about creating and displaying RFGs available here: https://toolset.com/documentation/getting-started-with-toolset/creating-and-displaying-repeatable-field-groups/
Hi Christian,
Thanks for your quick answer. I will look at he RFG approach. But before that I want to ask you this.
If it's designed to store the url of the file can I show the url then? And how should I do that?
Of course, you can use different attributes in the Type Field shortcode to output the link using the file URL instead of the "title" attribute:
[types field='bestand' separator='<br />'][/types]
Notice that I also changed the "separator" value to add a line break after each item, since you said you want to show them in a column. Feel free to change it back to ", " if you prefer a comma-separated list.
Hi Chris, that was easy ?, but it feels a little bit like a bad idea to have this url out in the open. Is there a way to omit the first part (=hidden link)? This will be equal for all uploaded files. If it s complicated do not bother, I am pretty happy already with your help and solution
hidden link
You could use the wpv-for-each shortcode to loop over the repeated fields and output something more custom. I have a custom shortcode that can help you show just the file name without the full URL path. Add this code to your child theme's functions.php file, or create a new snippet in Toolset > Settings > Custom Code:
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 use wpv-for-each to loop over the fields and output custom links:
[wpv-for-each field="wpcf-bestand"]
<a href='[types field="bestand" output="raw"][/types]'>[my_file_name file_url='[types field="bestand" output="raw"][/types]']</a><br />
[/wpv-for-each]
Hi Christian,
Your snippet nicely shows the name of the file, only the link does not work. See the screenshot.
I'm not able to see the rekenen-met-coordinaten snippet, but the other 3 snippets I tested have links with accurate URLs:
hidden link
hidden link
hidden link
Were you able to resolve this issue on your own? If not, how can I see the problem?
Because this site is life I changed the code back to the situation you see where the whole url is shown. The snippet you gave me
[wpv-for-each field="wpcf-bestand"]
<a href="[types field="bestand" output="raw"][/types]">[my_file_name file_url='[types field="bestand" output="raw"][/types]']</a>[/wpv-for-each]
shows only the last part of the url (what I wanted), but then the link does not work anymore.
I have changed it again to that situation so please check it out again.
The page was pending and is now published: hidden link
It looks like the quotation marks are nested incorrectly in your snippet. Try exactly what I pasted before:
[wpv-for-each field="wpcf-bestand"]
<a href='[types field="bestand" output="raw"][/types]'>[my_file_name file_url='[types field="bestand" output="raw"][/types]']</a><br />
[/wpv-for-each]
My issue is resolved now. Thank you!