Allowing user-defined sorts in shortcodes

7 views
Skip to first unread message

Doug Palmer

unread,
Jan 2, 2017, 12:16:39 AM1/2/17
to Omeka Dev
Greetings and Salutations, again.

I'm looking at adding user-selected sort to the [items] shortcode for the BigStuff theme. What I've ended up with is putting a wrapper around shortcodeItems. So, in functions.php, I have the code:

/** Wrap the sortable shortcode */
add_shortcode('items', 'bigstuff_sortable_items_shortcode');

...


function bigstuff_sortable_items_shortcode($args, $view) {
    $sortLinks = array(
        __('Title') =>'Dublin Core,Title',
        __('Creator') => 'Dublin Core,Creator',
        __('Date') => 'Dublin Core,Date',
        __('Date Added') => 'added'
    );
    $sort_field = Zend_Controller_Front::getInstance()->getRequest()->getParam('sort_field') ?: 'added';
    $sort_dir = Zend_Controller_Front::getInstance()->getRequest()->getParam('sort_dir') ?: 'a';
    $args['sort'] = $sort_field;
    $args['order'] = $sort_dir;
    $content = '<div class="item-shortcode">';
    $content .= '<div id="sort-links"><span class="sort-label">' . __('Sort by: ') . '</span>' . browse_sort_links($sortLinks) . '</div>';
    $content .= '<div class="item-list">';
    $content .= Omeka_View_Helper_Shortcodes::shortcodeItems($args, $view);
    $content .= '</div></div>';
    return $content;
}

The result is a list with a set of sort options at the top, similar to what appears in the item browse list. Have I done anything unspeakably heinous here? Or, even if not inherently evil, is there a better way of adding to the codes? Doug

Reply all
Reply to author
Forward
0 new messages