Plugin Planet

Premium WordPress Plugins

This tutorial explains how to display a link to any image or other file submitted with USP Pro.

For example, let’s say that you have a form that requires users to submit a PDF file along with their other information. With each post that is submitted, you will see the submitted PDF in the Media Library and also attached to the post as a Custom Field.

To display a link to the PDF (or any type of file), we can use any relevant shortcode or template tag. In order to automate things as much as possible, using a template tag is going to be your best bet for displaying links to submitted files. There are plenty of USP Pro tags and WordPress tags available that will enable us to make it happen.

Display a link via template tag

Using template tags requires a quick edit to your theme template. For example, let’s say that we want to display file links in the single view of the submitted post. In most themes, single.php is responsible for displaying the content of single post views. Although it may be that your theme uses some other file, such as content.php or similar.

Pro Tip: Master the WordPress theme template with my book, WordPress Themes In Depth. Equip yourself with the skills needed to customize and build your own WordPress themes!

Once you have located the theme file that is responsible for displaying the desired page view (e.g., the single post view in our example), add the following template tag anywhere in the WordPress Loop:

<?php $files = usp_get_submitted($postId);

foreach ($files as $file) echo '<a href="'. $file .'">View this Document</a>'; ?>

Alternately you can use do_shortcode(), like so:

<?php echo '<a href="'. do_shortcode('[usp_submitted]') .'">View this Document</a> '; ?>

There are other template tags that can work as well, such as WP’s native get_post_meta() and others.

Other file types

To display links to other file types, consider the following:

<?php $files = usp_get_submitted($postId);

foreach ($files as $file) echo '<a href="'. $file .'">View this Document</a>'; ?>

This code is used in our previous example to display a link to the file(s) that are uploaded to the submitted post. This gives us some code that we can use to display other types of files, such as images:

<?php $files = usp_get_submitted($postId);

foreach ($files as $file) echo '<img src='. $file .'" alt="">'; ?>

That will display all images that are attached to the submitted post. To go further with the example, here is how we can modify the code to display a list of links to all of the images:

<?php $files = usp_get_submitted($postId);

echo '<ul>';

foreach ($files as $file) echo '<li><a href='. $file .'">'. $file .'</a></li>'; 

echo '</ul>'; ?>

This is just the tip of the iceberg, so feel free to experiment with other code, tags, and file types.