Hello!
I want show the real file name (without URL) in file field like a link, how to?
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]"]
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?
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);
}
How to implements without shortcode?
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>
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.
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.
Hi Adriano, the code returned error:
Warning: explode() expects parameter 2 to be string, array given
In firebug i have a empty link:
Thank you again.
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!
Ah nice! You are welcome.