Templates

Templates are used to embed details of files in to a post or page. They are can also be used to create file lists. WP-Filebase includes a powerful template engine supporting IF-THEN-ELSE blocks. Templates are blocks of HTML code containing variables. There are three different types of templates:

  • File Templates are used to embed files
  • Category Templates are used for categories in file lists if file grouping is enabled
  • List Template consists of a Header, Footer and a File and Category Template.

Special templates that cannot be deleted:

  • Default: Default templates are used when there is no template specified, for example a shortcode without the tpl parameter. Its also used for file search results and attachments. Note that the default templates appears in the template management list as well as in settings. When resetting settings, the default template code is restored!
  • Filebrowser: template used for AJAX treeview
  • Filepage: This template is used to build the File Details Page (WP-Filebase Pro)

You can even place shortcodes into templates to build advanced file lists. Be careful: don’t nest a shortcode using the template itself!

Syntax

A template is a piece of HTML code containing “variables” that will be replaced with file specific properties. A variable is wrapped by two % characters, i.e. %file_name%. A very simple template:

<p>
<img src="%file_icon_url%" style="height:20px; vertical-align:middle;" />
<a href="%file_url%" title="Download %file_display_name%">%file_display_name%</a> (%file_size%)
</p>

This would output a HTML paragraph containing a small icon/thumbnail followed by the name and size of the file.

To omit the <img> tag for files without a thumbnail, an IF-block is added:

<p>
<!-- IF %file_thumbnail% -->
<img src="%file_icon_url%" style="height:20px; vertical-align:middle;" />
<!-- ENDIF -->
<a href="%file_url%" title="Download %file_display_name%">%file_display_name%</a> (%file_size%)
</p>

 

 

Inside an IF expression you can use the Boolean operators OR and AND. The following sample inserts a link to the associated post/page of the file if: 1. the file has an associated post and 2. the currently viewed post/page is not the associated one. So the link won’t appear in templates that are generated in the post/page of the file:

<!-- IF %file_post_id% AND %post_id% != %file_post_id% -->
<a href="%file_post_url%">%'View post'%</a>
<!-- ENDIF -->

Templates are internally parsed to PHP code, so all PHP and WordPress functions can be used in expression!

Template Variables

The following template variables are available for file and category templates:

NameDescriptionTypeExample Value
%uid%A unique ID number to identify elements within a templateNumber3
NameDescriptionTypeExample Value

Here’s a list of template variables for files, which can be selected from the Drop-Down when editing a template. Custom fields (see Settings) appear at the end of the Drop-Down box.

NameDescriptionTypeExample Value
%file_name%The name of the file (with extension)numberexample.pdf
%file_size%ID of the current post or pageFormatted size1.63 MiB
%file_date%Formatted date of the file (change in Settings)Formatted date time4. May 2011
%file_thumbnail%The name of the thumbnail fileStringexample-100×120.png
%file_display_name%The Title of the fileStringExample Document
%file_description%File DescriptionString
%file_version%File VersionString2.1
%file_author%File AuthorString
%file_languages%A comma-separated list of all supported languagesStringsEnglish, German
%file_platforms%A common-separated list of supported platformsStringsWindows 7, Ubuntu
%file_requirements%A commo-sperated list of requirementsStringsApache, MySQL
%file_license%File LicenseStringCreative Commons
Number-1
String (user role)Subscriber
%file_user_can_access%Boolean (0/1)0
%file_offline%Boolean (0/1)1
%file_direct_linking%Boolean (0/1)
%file_category%String
%file_post_idnumber

 

If ID3 detection is enabled, there are more variables available for each file. ID3 variables begin with the prefix %file_info/ . Example to get artist of an mp3 file:

%file_info/tags/id3v2/artist%

These variable can also be used in IF expressions. You’ll find a list of all available variables below the file form when editing a file.

Special template variables

%dl_countdown% Used in File Details Page template to display the countdown

%search_form% Used in list headers and footers to display a search form

%sort_link:file_sizeWill be replaced by a URL to sort the current file list. Example:
<a href="%sort_link:file_name%">Sort by Name</a>

%print_script:{script-name}% Used in list headers to include JavaScripts like the jQuery extension dataTables.

%print_style:{style_name}% Used in list headers to include CSS files.

Useful Expressions

Only display ads (or anything else) to non-registered users:
<!-- IF get_current_user_id() != 0 --> ..ad code.. <!-- ENDIF -->

PHP Code in Templates

WP-Filebase Pro supports PHP codeblocks inside the Template code. To use a template variable in PHP, use the following syntax (instead of %file_display_name%):
<?php echo $file->get_tpl_var('file_display_name'); ?>

56 thoughts on “Templates

  1. MIssvel says:
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)

    |

  2. gokhan says:
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)

    If pro filebase you give me a code will add subscribers to file in writing

  3. Jordan says:
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)

    I would love to use WP-Filebase in my site’s templates. Is there any support for using PHP code instead of shortcodes to accomplish this? Such as ‘public_downloads’,view=>’table’));?> or something of that nature? It seems limiting to only be able to use shortcodes to retrieve files and categories.

    Thank you,
    -Jordan

    1. Fabian says:
      VN:F [1.9.22_1171]
      Rating: 0 (from 0 votes)

      Hello Jordan,

      put
      in your template.

      Regards
      Fabian

      1. Heza says:
        VA:F [1.9.22_1171]
        Rating: 0 (from 0 votes)

        hie i would like to replace the id number on a short tag with a custom meta tag so i can put the id number in ther field if i want to use the shortcode as a link example like this but this one doesn’t work it takes me to the same page

        1. Heza says:
          VA:F [1.9.22_1171]
          Rating: 0 (from 0 votes)

          ,,

  4. Glen says:
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)

    Right now, unregistered users see something like this:
    file1
    file2
    file4
    file6
    file7

    Note that file3 and file5 are not shown because the user doesn’t have ACCESS to them..

    But, I’d like to be able to display files that users don’t have access to, as a way of getting them to register.. but I don’t want the files to be downloadable.. so you’d see something like:

    file1
    file2
    file3 *Upgrade to be able to download*
    file4
    file5 *Upgrade to be able to download*
    file6
    file7

    etc.. I know that I can use access levels to make files not appear, but I want them to appear, but instead be unclickable or use a different template.

    I know PHP well, I just need to know where to start.

    Thanks
    Glen

    1. Fabian says:
      VN:F [1.9.22_1171]
      Rating: -1 (from 1 vote)

      Hello Glen,

      to archive this, use the template Variable %file_user_can_access%, e.g put this in your template:
      <!-- IF !%file_user_can_access% --> *Upgrade to be able to download* <!-- ENDIF -->

  5. dannyboy says:
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)

    Hello, i would like to change the font color of the “Table Data” without modifying the main template of my website…..I have a plugin to add custon CSS to each pages…thanks !

  6. VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)

    I’m showing all categories with their titles, however the category template only wraps the category name and not the files that are in the category too. Is there anyway to wrap that category in a ? otherwise i’m getting files all over the place & no order, and using nth-child to sort them out doesn’t work because they aren’t in a container to reset the nth-child.

    1. VA:F [1.9.22_1171]
      Rating: 0 (from 0 votes)

      I’ve found a solution, in the File List template, using the header and footer as a then in the category template, starting it with and starting a new div will then wrap the categories, it’ll give an extra empty div, but unless there’s a better way of doing it, that way will do great for now 🙂

  7. Charles says:
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)

    Hi,

    I’m having trouble showing categories with no files. I have a structure like this:
    -Main Folder1 (0 direct files/ 4 total files)
    –Sub Folder1 (2 direct files)
    –Sub Folder2 (2 direct files)
    -Main Folder2 (1 direct file/ 7 total files)
    –Sub Folder3 (1 direct files)
    –Sub Folder4 (5 direct files)

    And I want to create a list/table that shows all the main folders. But the problem is that Main Folder1 does not show up because there is not “direct files” under it.

    Can you help me? Am I doing something wrong?

    Much thanks!

  8. Brian says:
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)

    How can I change the wordpress page template for the default file page? It’s set to default and I’d like to change it.

    1. Fabian says:
      VN:F [1.9.22_1171]
      Rating: 0 (from 0 votes)

      Hello Brian,

      see //wpfilebase.com/how-tos/filepage-custom-single-template/ .

      Regards
      Fabian

  9. VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)

    Hi,
    I’m trying to make use of a special template variable %sort_link:file_size%, and combine this with the id3-tags which is displayed with %file_info/tags/id3v2/artist%. The result of this would be %sort_link:file_info/tags/id3v2/artist%. The problem is that the slashes (/) in the id3-format breaks the link. Is there a possible workaround?

  10. Thomas says:
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)

    I wonder if it’s possible to create a collapsable list of categories. i’m talking about a list with 300 files in 17 categories. If there’s instant search I’d be more than happy.

    /t

Leave a Reply

Your email address will not be published.