Skip Navigation

[Resolved] Displaying uploaded files as icons with file name instead of url link

This support ticket is created 6 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 6 years, 9 months ago.

Assisted by: Luo Yang.

Author
Posts
#627018

J S

Tell us what you are trying to do?

For the CPT "Submissions", I'd like to display an file type icon and file name as a downloadable link for any uploaded files. By default in using the file shortcode [types field='file' link='true' separator=' '], the file just shows as a url link.

Surely I am not the first to request this....Is this possible? thanks

#627175

Hello,

There isn't such a built-in feature within Toolset plugins, but you can setup a custom shortcode to retrieve the file extension from custom field, for example, I assume it is a multiple instance custom file field "file", which is created with Types plugin, you can try these:
1) create a custom shortcode [get_mime_type], put below codes into your theme/functions.php:

add_shortcode('get_mime_type', 'get_mime_type_func');
function get_mime_type_func($atts, $content = ''){
	// Attributes
	extract( shortcode_atts(
		array(
			'option' => 'extension',
		), $atts )
	);
	$content = wpv_do_shortcode($content);
	$path_parts = pathinfo($content);
	$res = '';
	if($path_parts[$option]){
		$res = $path_parts[$option];
	}
	return $res;
}

You can get the file extension, file name by specifying the shortcode attribute, for example:
[get_mime_type option="basename"] ... [/get_mime_type]
hidden link

2) Dashboard-> Toolset-> Settings-> Front-end Content
in option "Third-party shortcode arguments", fill the shortcode name: get_mime_type

3) In a single "Submissions" post content, output the file name as the link text, and output file extension as a CSS class name, output file URL as the link target.
using below codes:

<ol>[wpv-for-each field="wpcf-file"]
<li><a href="[types field="file" output="raw"][/types]" ><span class="[get_mime_type][types field="file" output="raw"][/types][/get_mime_type]">[get_mime_type option="basename"][types field="file" output="raw"][/types][/get_mime_type]</span></a></li>
[/wpv-for-each]</ol>

4) You will get the file extensions as below:

<ol>
<li><a href="<em><u>hidden link</u></em>"><span class="zip">file1.zip</span></a></li>
<li><a href="<em><u>hidden link</u></em>"><span class="gif">file2.gif</span></a></li>
</ol>

Then setup custom CSS codes to display the icons as what you want, for example:

More help:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-for-each
Iterate through multiple items in a post meta field and output the enclosed text for each item. Including Types repeating fields.