Skip Navigation

[Resolved] [types field]

This thread is resolved. Here is a description of the problem and solution.

Problem:

I want to display only the filename (not the full URL) from a Toolset file field using a shortcode and also show a message if there are no files.

Solution:

Create a custom shortcode using PHP to extract the filename with basename($url), then use Toolset’s [wpv-conditional] shortcode to check if the field has content and show either the filenames or a fallback message.

Relevant Documentation:

https://toolset.com/forums/topic/truncate-file-full-path-url-to-only-filename/

https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

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.

This topic contains 2 replies, has 1 voice.

Last updated by Christopher Amirian 1 week, 5 days ago.

Assisted by: Christopher Amirian.

Author
Posts
#2808323

Tell us what you are trying to do?
- Output a link wth only the filename on a [types field].

Is there any documentation that you are following?
- I thougth I could use something like format="%%TITLE%%" but the block gets invalid as I modify it

Is there a similar example that we can see?

[wpv-for-each field="wpcf-adicionales"][types field='adicionales' output='normal'][/types][/wpv-for-each]

Outputs a link to: hidden link
I need to output a link with only the filename and not all the URL.

It would be nice to find some documentation that adresses that shortcode argument but I cant find it

What is the link to your site?
sorry, It's private.

#2808329
#2808333

Sorry guys, another question... how can I add a notice if there are no documents?

[wpv-for-each field="wpcf-otros-documentos"]
[get_file_name_custom url="[types field='otros-documentos' output='raw'][/types]"]<br>
[/wpv-for-each]

The above shortcode works, but shows nothing if there is no files.

#2808487

Christopher Amirian
Supporter

Languages: English (English )

Hi,

Welcome to Toolset support. There is no default functionality in Toolset to extract filename from URL. That is considered a custom development.

You can hire a developer to do so:

https://toolset.com/contractors/

In general you will need a custom shortcode for that. Something like this:

function get_file_name_custom_shortcode($atts) {
    $atts = shortcode_atts(array('url' => ''), $atts);
    $url = $atts['url'];
    if (empty($url)) return '';
    return basename($url);
}
add_shortcode('get_file_name_custom', 'get_file_name_custom_shortcode');

And the usage of shortcode should be something like this:

[wpv-for-each field="wpcf-otros-documentos"]
    [get_file_name_custom url="[types field='otros-documentos' output='raw'][/types]"]<br>
[/wpv-for-each]

This loop will display only the filenames of the files in the otros-documentos field.

Please note: We did not test the code above. It is just to give you an idea how you need to go forward.

To show a message when there are no files in the otros-documentos field, you can use Toolset's conditional shortcodes. Here's how:

[wpv-conditional if="( $(wpcf-otros-documentos) ne '' )"]
    [wpv-for-each field="wpcf-otros-documentos"]
        [get_file_name_custom url="[types field='otros-documentos' output='raw'][/types]"]<br>
    [/wpv-for-each]
[/wpv-conditional]

[wpv-conditional if="( $(wpcf-otros-documentos) eq '' )"]
    <p>No documents available.</p>
[/wpv-conditional]

Thanks.