Skip Navigation

[Resolved] I have custom field type as PDF file, I want to file title for it's link

This support ticket is created 5 years, 1 month 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 10 replies, has 2 voices.

Last updated by kristoferJ 5 years, 1 month ago.

Assisted by: Shane.

Author
Posts
#1367929
product custom field2.jpg
product custom field1.jpg

I am trying to:
There is no option to show file title for it's link when I select to show custom field which is PDF file type. It shows full link. I want file title as it's anchor text.

Link to a page where the issue can be seen:

I expected to see: File title as anchor text, I can't enter it manually as a product post as it's own files and there are plenty of products.

Instead, I got:

#1368021

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Kristofer,

Thank you for getting in touch.

Currently there isn't a way to get this information for file upload fields.

What I recommend that you do is to have a separate field that would hold the title of the PDF file.

This way you can use that field to provide a title for the PDF on the frontend. Also I would recommend that you open a feature request ticket so that this can be reviewed and added because it is available for image fields.
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

Thanks,
Shane

#1368913

How this is possible? "What I recommend that you do is to have a separate field that would hold the title of the PDF file."

#1369007

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Kristofer,

So it would function like this. Essentially the file field and the title field i.e another single line field will be a pair.

If the user uploads their PDF file, under that there will be another single line field under that PDF field to enter the title to display.

From this you can then display the field title on the frontend.

Example


<a href="[types field='file-field' output='raw'][/types]">[types field='title-field'][/title]</a>

This should generate a link to the PDF file with title as the link name.

Please let me know if this is a little bit more clearer for you.

Thanks,
Shane

#1369053

That shortcode has title as end tag which seems to be wrong and it's not clear to me.

#1369057

These files will not be uploaded by frontend user, files are uploaded by admin.

#1369157
#1369285

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Kristofer,

These custom codes are giving the file name and not the name given to the file after it is uploaded.

Is it that the Admin creates a new post and uploads the file to the field ?

Rather than using custom code just having another field there for them to enter the name of the file and then display this on the frontend would be a more longer sustainable solution because if the code breaks then we won't be able to fix it since it is custom code.

E.g

-----File Field------
My PDF is Uploaded Here
-----------------------

-----PDF Title Field-------
Sample PDF
---------------------------------

So the admin will upload the file first then in another field define the title of the file.

Please let me know if you understand where i'm getting at.

Thanks,
Shane

#1369305

All files are already uploaded, there are number of files, I can't manually add title for each. And that is why I think toolset has options for views and fields to make it easier. Please connect me to a different support team member.

#1369403

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Kristofer,

Unfortunately i'm the only supporter available at the moment. However I took a look at the custom code for you.


/* --------------------------------------------- */
// CUSTOM SHORTCODE TO GET FILE NAME FROM PATH
// keywords: file, name, shortcode, path, explode, file_url
// [my_file_name file_url="/path/to/file.ext"]
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);
}


To use this shortcode you will do this [my_file_name file_url="[type field='my-pdf' output='raw'][/types]"]

This will output the filename of the pdf, so if the file url is test.com/my-file.pdf then it will return my-file.pdf as the name.

To construct this on the frontend you will need to do this


<a href="[type field='my-pdf' output='raw'][/types]">[my_file_name file_url="[type field='my-pdf' output='raw'][/types]"]</a>

This will generate a link with the file name as the Link.

Add the custom shortcode to your toolset custom shortcode option in Toolset -> Settings -> Custom Code and ensure that it is activated.

Please let me know the results of this.

Thanks,
Shane

#1370393

My issue is resolved now. Thank you!