Gallery offers a theme setting that enables the display of an individual album's or item's custom field block. However, if you'd like to display an item's custom fields next to its thumbnail in an album, try one of the following theme modifications.
If you only need to display a few custom fields you may use the customfield.LoadCustomFields callback. This method requires a simple edit to your theme's album.tpl file.
Important: If you're editing one of Gallery's stock themes, review How to Edit an Existing Theme.
{* Use the customfield.LoadCustomFields callback to get an array of fields *} {g->callback type="customfield.LoadCustomFields" itemId=$child.id} {if !empty($block.customfield.LoadCustomFields.fields.Item)} <ul> {foreach from=$block.customfield.LoadCustomFields.fields item=customField} <li>{$customField}</li> {/foreach} </ul> {/if}
After saving album.tpl, you should now see all available custom fields next to items in your album pages. Callbacks are easy to implement and work well. If you have a high-volume web site and performance is a concern, load custom field data in your theme's theme.inc file.
High-traffic sites that display a large number of items will benefit by loading custom fields in theme.inc instead of using a callback.
/* Get custom fields */ list ($ret, $children) = GalleryCoreApi::loadEntitiesById($childIds); if ($ret) { return array($ret, null); } list ($ret, $theme['customFieldValues']) = CustomFieldHelper::fetchFieldValues($children, 'detail'); if ($ret) { return array($ret, null); }
Next, display custom fields in album.tpl
{* Show a child's custom fields *} {if isset($theme.customFieldValues[$child.id])} <ul> {foreach from=$theme.customFieldValues[$child.id] key=name item=value} <li>{$name}: {$value}</li> {/foreach} </ul> {/if}