hook( "displayersList", "register_linked_onebyone" );
This code hooks into the ''displayersList'' anchor and attaches a function called ''register_linked_onebyone'' which will handle adding our custom displayer to the list:
function register_linked_onebyone( $displayers )
{
// Key is displayer title, value is slug, same as folder name
$displayers['Linked One by One']= "linked-onebyone";
return $displayers;
}
If you save this and upload the plugin to your plugins folder, login to your Secretary installation and select a project to edit, you will now see your displayer in the dropdown!
===== Step 4: On the frontend =====
An essential part of the plugin is missing at this point: the function that will handle outputting images on the frontend.
This function receives three values from the system: the project array, an array of all files in the project, and an array describing the current group. Essentially, this function loops through all the files and matches them with the current group, so that files and groups set up in the backend are recreated on the frontend:
function linked_onebyone( $project, $files, $group )
{
global $clerk;
// Loop through the files
foreach ( $files as $file => $data )
{
// Match the file's group with the group number
// Does this file belong to this group?
if ( $data['filegroup'] == $group['num'] )
{
// Yes. Do some cool shit now.
}
}
}
**Note that the function name must match the folder name, the only difference being that dashes are underscores.**
Now we move on to file handling. Displayers need to be able to handle all file types: images, video and audio.
function linked_onebyone( $project, $files, $group )
{
global $clerk;
// Loop through the files
foreach ( $files as $file => $data )
{
// Match the file's group with the group number
// Does this file belong to this group?
if ( $data['filegroup'] == $group['num'] )
{
// Define file width and height for proper CSS
$width= ( $data['width'] == 0 ) ? "auto" : $data['width'];
$height= ( $data['height'] == 0 ) ? "auto" : $data['height'];
// Handle the different file types
switch ( $data['type'] )
{
case "image":
$html.= '
';
break;
case "video":
$html.= '' . mediaplayer( $data, $project );
break;
case "audio":
$html.= '' . audioplayer( $data, $project );
break;
}
}
}
}
To handle the different file types we use a ''switch'' statement. The video and audio cases will always make use of the built in media and audio players (unless you want to provide your own). So that leaves most customization to the image case, which by default will always just spit out an ''img'' tag.
The ''src'' attribute for images is in this format: ''[path_to_projects_folder]/[project_slug]/[file_name]''