Getting the Collection name in /items/browse?collection=?

Howdy!

I’m creating a new theme and am trying to customize browse.php in the items folder. What variables are being passed that I can use to get the Collection when that is part of the querystring?

I see $total_results and items and the helper public_nav_items() returns a ul with an li using the class collection where the Collection name is rendered but how can I get either the Collection id passed in the querystring to look up the Collection or is there an existing object on the page with the Collection information?

Thanks!

I think you’re actually looking at item_search_filters(), which produces a ul from the query string. I don’t think you need anything in that though.

You can get the collection id via $_GET, then use that with get_record_by_id() to get the collection record. I think that should get you what you’re looking for.

Here’s an example that does all that for use with record_image() to show the collection thumbnail.

<?php 
if (isset($_GET['collection'])) {
    $collectionId = $_GET['collection'];
    $collectionRecord = get_record_by_id('collection', $collectionId); 

    echo record_image($collectionRecord, 'square_thumbnail');
}
?>

Thanks for the response!

Unfortunately that’s not what I’m trying to do. I’m on the page browse.php under items and it has been passed the querystring collection=? where the question mark is the number of the collection it uses to filter the results rather than showing all items it only shows the items within that Collection. URL on my test site is http://localhost/items/browse?collection=3.

There’s a function item_search_filters() that generates this HTML:

<div id="item-filters">
    <ul>
        <li class="collection">Collection: Archon</li>
    </ul>
</div>

The collection name (in this case Archon) is what I want as I want to incorporate it into the breadcrumbs and page title rather than have it placed by this function. If it comes down to it I will just parse the querystring myself and fetch the Collection by that ID but it seems to me if the item_search_filters() function works without parameters it must know what Collection is involved so I’m hoping there’s an existing variable on the page with that Collection name or the ID I can use for the lookup.

What Kim wrote above is how you’d do this. In her example you’d just change the record_image line to something like echo metadata($collectionRecord, array('Dublin Core', 'Title')); to print the collection title rather than show the image.

item_search_filters is just doing the same basic process internally.

1 Like

Thanks so much to you and Kim. I have everything working as I’d hoped. Now for another request :stuck_out_tongue:

How would I do the same for tags? I took a swing with

if (isset($_GET['tag'])) {
	$tagId = $_GET['tag'];
	$tagRecord = get_record_by_id('tag', $tagId);
}

but had no luck.

If all you need is the tag name, you can get it from the query string and clean it up with html_escape().

if (isset($_GET['tags'])) {
    $tagName = html_escape($_GET['tags']);
}

So using that example, a URL like http://myproject.org/omeka/items/browse?tags=American+periodicals should produce “American periodicals”.

1 Like