How to use the ‘Custom Fields’

Starting with v2.0 (April 25th, 2013), PHP Melody has the ability to assign custom fields to each video, article or page. This extra data is also known as meta data and it can include data such as:

  • Artist: Michael Jackson
  • Speaker: Thomas K.
  • Episode: #7
  • Season: #2
  • Video Part: #1

These are merely a few examples of the possible uses for ‘custom fields’ or, as otherwise known: meta data. Custom fields are user defined, meaning you can define any meta data relevant to the video, article or page posted.

Custom fields come in name/value pairs. The name is the identifier while the value is the actual information you wish to display on the page. In the first example, “Artist” is the name while “Michael Jackson” is the value.

Custom Fields Usage

Assuming we have a music video website, we’re going to add a new ‘custom field’ named artist. The following steps need to be taken to add the new ‘custom field’:

  1. After you’ve added/edited your video scroll to the bottom of the page to the area titled Custom Fields.
  2. In the first text field, titled ‘Custom name’, enter artist and in the second text field, titled ‘Custom value’, enter “Michael Jackson” or the artist associated with the video.
  3. Click the Add Custom Field button to assign this ‘custom field’ to the video before saving.

Custom Fields

The next time you post a video you can select the alredy created artist field by clicking the ‘Select Existing Field’ link within the Custom Fields form.

You can add as many custom fields as your site requires.

Displaying Custom Fields

Once defined, you will have to output the value for this new ‘custom field’ on the actual page your visitors will see. This can be done by inserting some additional code into your theme. In our case, we will add the artist filed in the title of the page after the video name.
For this, we need to edit the /templates/default/video-watch.tpl file:

—————[ FIND ]—————


—————[ REPLACE WITH ]—————

<h1>{$video_data.video_title} {get_video_meta video_id=$ key='artist'}</h1>

As underlined in the replacement code, the KEY was set to the ‘Custom Name’. In our case it was artist, as previously defined in the Admin Area (video editing/adding form).

If we define another custom field, named season, we will use:

{get_video_meta video_id=$ key='season'}

This code can be placed anywhere in the video-watch.tpl file and even styled with some CSS afterwards.

Note: this example was for a video page. To use the custom fields on an article page (i.e. article-read.tpl), the code would be:

{get_video_meta video_id=$ key='season'}

Additional usage

If you have more than one custom field, you can list them all in an ordered list (<ul>) by using this following code in video-watch.tpl:

{get_video_meta_list video_id=$}

or in article-read.tpl:

{get_article_meta_list article_id=$}