Tags by collection

Is it possible to filter tags by collection? I would like this page (http://omeka.wustl.edu/omeka/items/tags) to only show tags from our Ferguson collection, but can't figure out a way to do it.

There's not a really good way to do it, but it could be done with a simple plugin. Create a folder in your plugins directory called TagsByCollection, and a file in there called TagsByCollectionPlugin.php

Put this in that file, and replace the $collectionId with the collection you want to use (looks like 62 in your case)

class TagsByCollectionPlugin extends Omeka_Plugin_AbstractPlugin
{
    protected $_hooks = array('tags_browse_sql');

    public function hookTagsBrowseSql($args)
    {
        $select = $args['select'];
        $collectionId = 119;
        $select->where("items.collection_id = ?", $collectionId);
    }
}

When you activate the plugin, it should do what you want.

Keep in mind that this would break the usual function of that page, so people coming to the site might expect tags from items in other collections to be there.

Thanks. I followed your instructions but can't activate the plug-in. It says "The TagsByCollection plugin cannot be loaded for the following reasons:
The plugin.php file is missing."

ah...what version of Omeka are you running? I'm pretty sure that if it is earlier than 2.0, that would explain the difference.

Yep, we have 1.5, I believe

So, I _think_ this will work. A very basic check looked okay, but it's probably worth doing more checking to see if surprises turn up.

In the same TagsByCollection folder, get rid of the file that's there, and create a plugin.php file with this in it:

<?php
function tags_by_collection($select, $params)
{
    $db = get_db();
    $collectionId = 62;
    $select->joinInner(array('items'=>$db->Items), "tg.relation_id = items.id", array());
    $select->where("tg.type = ?", 'Item');
    $select->where("items.collection_id = ?", $collectionId);
}

add_plugin_hook('tag_browse_sql', 'tags_by_collection');

Worked great - thank you!