Skip Navigation

[Resolved] How to show the File Name in "File Field"?

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 9 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 -
- - - - - - -

Supporter timezone: America/Sao_Paulo (GMT-03:00)

This topic contains 10 replies, has 2 voices.

Last updated by Adriano 9 years, 8 months ago.

Assisted by: Adriano.

Author
Posts
#230590

Hello!
I want show the real file name (without URL) in file field like a link, how to?

#230594

Dear Angelo,

Using native Toolset features you can't do that. But with a custom shortcode, you can:

add_shortcode( 'my_file_name', 'my_file_name_func');
function my_file_name_func($atts)
{
extract( shortcode_atts( array(
'file_url' => '',
), $atts ) );
$arr = explode('/',$url);
return end($arr);
}

This code should be goes in functions.php file. You could call it like this: [my_file_name file_url="[types field='the full url' raw=true][types]"]

#230611

Hi!
Thanks for fast reply!

My code is:

[code]
types_render_field("anexos", array('raw' => 'false', 'output' => 'html', 'show_name' => 'false', "link" => 'true', "title" => 'Download', "separator" => "</li><li>"));
[/code]

In functions.php i add:
[code]
add_shortcode( 'anexos', 'my_file_name_func');
function my_file_name_func($atts)
{
extract( shortcode_atts( array(
'file_url' => '',
), $atts ) );
$arr = explode('/',$url);
return end($arr);
}
[/code]

But not work =/

Any idea?

#230614

Sorry, this is correct code:
Call types:

types_render_field("anexos", array('raw' => 'false', 'output' => 'html', 'show_name' => 'false', "link" => 'true', "title" => 'Download', "separator" => "</li><li>"));

functions.php

add_shortcode( 'anexos', 'my_file_name_func');
function my_file_name_func($atts)
{
    extract( shortcode_atts( array(
        'file_url' => '',
    ), $atts ) );
        $arr = explode('/',$url);
        return end($arr);
}
#230797

How to implements without shortcode?

#230810

Dear Angelo,

Without custom code you can not achieve that. But without shortcode you can, but without use types_render_field() function:

<?php
$arr = explode('/',$url);
$file_name = end($arr);
?>
<a href="<?php echo get_post_meta(get_the_ID(), 'wpcf-file-field'); ?>"><?php echo $file_name; ?></a>
#233793

Hi Adriano! Thanks for your support.

My file field name is "anexos", i try:

<?php
$arr = explode('/',$url);
$file_name = end($arr);
?>
<a href="<?php echo get_post_meta(get_the_ID(), 'wpcf-anexos'); ?>"><?php echo $file_name; ?></a>

But no results is displayed.

#233950

Dear angelor,

Sorry, my code is wrong. Please use this one below:

<?php
$url = get_post_meta(get_the_ID(), 'wpcf-anexos');
$arr = explode('/',$url);
$file_name = end($arr);
?>
<a href="<?php echo get_post_meta(get_the_ID(), 'wpcf-anexos'); ?>"><?php echo $file_name; ?></a>

Please let me know if you are satisfied with my answer and if I can help you with any other related question.

#234000

Hi Adriano, the code returned error:

Warning: explode() expects parameter 2 to be string, array given

In firebug i have a empty link:

<a href="Array"></a>

Thank you again.

#234013

Hey!
My field is a repeater field, made ​​some adjustments and now works fine.

See:

                    $anexos = get_post_meta(get_the_ID(), 'wpcf-anexos');
                    foreach ($anexos as $anexos) {
                    $exp = explode('/', $anexos);
                    $filename = end($exp);
                        echo '<li>';
                        echo '<a href="'.$anexos.'" title="Anexo">';
                        echo "$filename";
                        echo '</a>';
                        echo '</li>';
                    }

Thanks!

#234019

Ah nice! You are welcome.

The forum ‘Types Community Support’ is closed to new topics and replies.

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