Sorting tags by collection for display/browsing


#1

Hello,

I am working on a collection (our library uses Omeka for a number of collections - no exhibits) and I have included tags on the items within our collection to make it easier for users to search for items. For example, I have included tags such as ‘2-5 players’ as this is a board game collection, users can use this tag to find other games that are 2-5 players.

When I was on our site, I went to the specific collection for board games and then went to “Browse by Tag”. Expecting a tag cloud of some sort I was surprised to see a huge tag cloud. The tag cloud has every tag from every collection viewable. Making it quite daunting for a user to sift through.

I am looking for a way to sort the tags by collection (all the board game tags, all the children book tags, etc.) and have this sorting reflected on the site so that when a user goes into the board game collection and clicks “browse by tag” they are only given the board game collection tags. Thus giving them a smaller and more manageable tag cloud to skim through.

Is this possible? I have looked at the “Edit Tags” section and see that I can sort in a number of ways but not group the tags by collection and display them with their specific section. If anyone knows of a way to do this I would greatly appreciate it!

  • Air

#2

It seems theoretically possible, but the best way to do it is an open question in my mind – I can see a couple different approaches, but they would all involve some level of coding up new features, either via a plugin, maybe a new custom theme function, or on our side a core feature addition.

Just to make sure I understand the details of the issue, am I following right that this is the sequence you are going through in navigating around?

1a. Start at a Collection page (with a URL that ends something like /collections/show/94
1b. Start on the Collection browse page ( URL like /collections/browse)
2. From either of those, there’s a link like “View Items in Whatnot Collection” (text differs, but go to the same page
3. Follow that link, and it gets you to a list of items in that collection (URL ends like /items/browse?collection=94
4. From the page in 3, you click “Browse by tag” and expect only the tags from Items in that collection, not all the tags?


#3

Yes, I start at 1b (/collections/browse) then from there step 2 click “view items in ____” and from there I am on the list of items in that collection (/items/browse?collection=7).

Then from that page, from step 3, I click the “Browse by tag” and expect/would like to see only the tags from the items in that collection, not all the tags from every collection. That way the user, in this case, could select the board game collection and browse by tag to look for, for example, all games tagged with “2-5 players”. Right now they still can, but it means scrolling through a lot of irrelevant tags in order to find that. Displaying only the board game tags would create a much smaller tag cloud and allow users to scan it easily for relevant tags.

Steps:

1b. fimsgrc.omeka.net/collections/browse
2. View Items in Board Games
3. http://fimsgrc.omeka.net/items/browse?collection=8
4. Browse by Tag – brings me here: http://fimsgrc.omeka.net/items/tags

So, in some way I’d like to be able to sort the tags into each respective collection, and then when user selects “Browse by Tag” they are only given the tags within that collection to search through. Or perhaps once a user has selected “Browse by Tag” and option can be available for them to limit what tags they see, and they can then select “Board Game Tags” or “View ____ Collection Tags”.


#4

Yeah, that makes sense. It sorta specializes the the usual process, so there’s a couple ways at it. I was curious about it, so I did some writing on a theme-centric approach, as opposed to a plugin-centric approach. More on that below.

This theme-centric approach will involve a lot of overriding default templates.

First, in your theme’s custom.php file (create it if it isn’t there), add these functions:


function get_tags_by_collection($collectionId)
{
    $db = get_db();
    $tagTable = $db->getTable('Tag');
    $itemTable = $db->getTable('Item');
    $select = $tagTable->getSelectForFindBy(array('type' => 'Item'));
    $itemTable->filterByCollection($select, $collectionId);
    $tags = $tagTable->fetchObjects($select);
    return $tags;
}

function contextual_public_nav_items(array $navArray = null, $maxDepth = 0)
{
    if (!$navArray) {
        $navArray = array(
            array(
                'label' =>__('Browse All'),
                'uri' => url('items/browse'),
            ));
            if (total_records('Tag')) {
                if (isset($_GET['collection'])) {
                    $collectionId = $_GET['collection'];
                    $queryParams = array('collection' => $collectionId);
                } else {
                    $queryParams = array();
                }
                $navArray[] = array(
                    'label' => __('Browse by Tag'),
                    'uri' => url('items/tags', $queryParams),
                );
            }
            $navArray[] = array(
                'label' => __('Search Items'),
                'uri' => url('items/search')
            );
    }
    return nav($navArray, 'public_navigation_items');
}

The first function will do the filtering of tags that you are looking for. That’s actually the easy part. Trickier is making the links work in the navigation tabs – that’s what the second one partly gets to.

With those in place in custom.php, you need to change or override the theme’s files that create the item navigation tabs. In items/browse.php, items/tags.php look for

<?php echo public_nav_items(); ?>

and replace it with

<?php echo contextual_public_nav_items(); ?>

That’ll use the new function in custom.php to add the correct link to the tags filtered by the collection.

Last, in tags.php add this code before the call to tag_cloud


<?php
    if(isset($_GET['collection'])) {
        $collectionId = $_GET['collection'];
        $tags = get_tags_by_collection($collectionId);
    }
?>

I think that covers everything, with the following caveat.

If you have any plugins that add to those tabs, this won’t work for them, so it’s a bit brittle. A plugin-centric approach would address that, but might add too much that isn’t necessary.


#5

Thank you very much for attempting a theme-centric approach, I really appreciate your help so far. I have searched our Omeka site for a way to do this, however, I am not entirely sure how to access the theme’s custom.php file. I don’t think I have access to this. Our site is created with this plan:

Basic (free): 500 MB storage; 1 site; 10 plugins (Exhibit Builder, Simple Pages, Coins, Library of Congress Suggest, Social Bookmarking, CSV Import, OAI-PMH Harvester, DocsViewer, Google Analytics, SharedShelfLink); 4 themes (Berlin, Minimalist, Season, Rhythm)

It is hosted on Omeka.net not through our own servers. As this is the case I don’t think I have access to code for the theme and therefore cannot reach or create a theme’s custom.php file. That is my current understanding of the situation and our site. If I am wrong, please let me know how I might access the theme’s files so that I can go in and add the functions.

If I cannot do this is there a way to do this via plugin for Omeka.net?

Thanks again for all your help so far!


#6

Ah…that does change things. Omeka.net questions are better directed to http://info.omeka.net/contact

The answer, though is that on Omeka.net sites, this isn’t really an option. You are right that you don’t have access to custom.php or other theme file. There’s also not a way to add a custom plugin.

That said, I’ll raise the question of adding some related options to the core Omeka code, so some options might appear sometime in the future.


#7

Thank you so much! I know our IT guy was interested in Omeka so perhaps we may look at going into omeka.org and hosting on our own server. :slight_smile:

Again though, thank you for all your help!


#8

Just tried it, and it works very well, so thanks @patrickmj.

One issue though is that if one, after choosing “Browse by Tag”, moves back to “Browse All” and then again to “Browse by Tag”, the filtering of tags gets lost and one’s back with all tags from all documents. Not sure it can be easily fixed.

If anyone comes up with a plugin-centric approach, please let me know as I’m quite interested in the topic. Thanks.