browse_sort_links — Get the list of links for sorting displayed records.¶
Summary¶
- browse_sort_links($links, $wrapperTags = array())¶
Get the list of links for sorting displayed records.
Parameters: - $links (array) – The links to sort the headings. Should correspond to the metadata displayed.
- $wrapperTags (array) – The tags and attributes to use for the browse headings - ‘list_tag’ The HTML tag to use for the containing list - ‘link_tag’ The HTML tag to use for each list item (the browse headings) - ‘list_attr’ Attributes to apply to the containing list tag - ‘link_attr’ Attributes to apply to the list item tag
Returns: string
Usage¶
Generates HTML elements for sorting based on the metadata given.
When the records are presented as a table, as in most admin browse views, $wrapperTags should be:
array('link_tag' => 'th scope="col"', 'list_tag' => '')
Otherwise, you will want to add text and/or styling to make clear that the list presented is for sorting the displayed records.
Examples¶
Use the links array to set the properties on which items can be sorted in the browse views. The labels are arbitrary, while the property names are determined by the element set or the record model.
<?php
$sortLinks[__('Title')] = 'Dublin Core,Title';
$sortLinks[__('Creator')] = 'Dublin Core,Creator';
$sortLinks[__('Date Added')] = 'added';
?>
<div id="sort-links">
<span class="sort-label"><?php echo __('Sort by: '); ?></span><?php echo browse_sort_links($sortLinks); ?>
</div>
Include the wrapperTags array when creating a sortable table, as in the admin view. Note that the column with the “Type” label is not sortable because no property name has been entered.
<?php
$browseHeadings[__('Title')] = 'Dublin Core,Title';
$browseHeadings[__('Creator')] = 'Dublin Core,Creator';
$browseHeadings[__('Type')] = null;
$browseHeadings[__('Date Added')] = 'added';
echo browse_sort_links($browseHeadings, array('link_tag' => 'th scope="col"', 'list_tag' => ''));
?>