Browse items header -- I want to display collection/tag name

I have read through and experimented with the API, but I am unable to figure out how to display the name of the collection or tag name when you are browsing items.

Currently... "Browse Items (## items)"
Desired ... "Browse Collection Name (## items)
or .... "Browse Tag Name (## items)

I'm seeing the ability to display the collection name when viewing an individual item, but not the full list.

As Omeka stands today, is there a means of doing this? Thanks!

http://www.mjcpl.org/photos

Hi mjcpl:

You could add some custom code to your items/browse.php file, something like this:

<?php
    if ($collection = get_collection_by_id($_GET['collection'])) {
        $html .= 'Collection: '.$collection->name;
    }
    if ($tags = html_escape($_GET['tags'])) {
        $html .= 'Tags: '.$tags;
    }

    echo $html;
?>

This is getting each of the parameters passed to the URL, and adding their values to a $html variable, then echoing that variable.

Best,
Jeremy

That was exactly what I needed. You are a scholar and a gentleman!

I'm learning php as I go. I understand what you did in general, but I'll need to read up on $_GET to "get it".

Thanks again!

Glad to help! $_GET is a reserved variable in PHP for retrieving variables passed to the URL:

http://php.net/manual/en/reserved.variables.get.php

Hi,

I am working with a similar situation. When I use this same code, however, it prints the words "Tags: Array" on browse pages such as items/browse/tags/tag+name. Do I need something else after the .$tags code?

The code reads:

<?php
    if ($collection = get_collection_by_id($_GET['collection'])) {
        $html .= ' '.$collection->description;
    }

    elseif ($tags = get_tags($_GET['tags'])) {
        $html .= 'Tags: '.$tags;
    }
    echo $html;
?>

Any suggestions would be much appreciated.

Thanks!

Hi cabusara,

If you change get_tags to html_escape in the elseifit should work OK. Was there a reason you wanted to use get_tags instead?

Best,
Jeremy

I am using get_tags because html_escape returns nothing (no error message, just a blank space on the page where the tags text should be).

I tried html_escape again just to double check, and indeed, the system returns nothing. So, neither get_tags or html_escape seem to work.

Just to get a larger picture of what is going on on the rest of the page's code, here is what things look like. Everything else is working, except for this get_tags (which returns Tags: array) and html_escape (which returns nothing).

<h1>
<?php
    if ($collection = get_collection_by_id($_GET['collection'])) {
        $html .= ' '.$collection->description;
    }

    elseif ($tags = html_escape($_GET['tags'])) {
        $html .= 'Tags: '.$tags;
    }
    echo $html;
?></h1>

<?php while (loop_items()) {
    switch (item('collection name')) {
    case 'Question1':
        common('browseq');
        break;
    case 'Question2':
        common('browseq');
        break;
    case 'Question3':
        common('browseq');
        break;
    case 'Question4':
        common('browseq');
        break;
    case 'Question5':
        common('browseq');
        break;
    case 'Forum Scholars':
        common('browses');
    default:
        common('browse');
    }

}
?>

The code as you have it should work if you have in fact returned a query string in the url, i.e. have something like browse?tags=lorem at the end of the url.

Are you trying to return the tags for an instance other than browsing items by a tag?

Aha, that gave me an idea. The tags urls are linking to pages with addresses like "/items/browse/tag/lorem"

I checked the command I am using to get the tag links on pages... I am using:
<?php echo item_tags_as_string(); ?>

This automatically links all my tags to pages with urls like "/items/browse/tag/lorem"

So, I went into the application/helpers/ folder and modified "TagFunctions.php" so that the section that reads

/**
 * Retrieve a tag cloud of all the tags for the current item.
 *
 **/

function item_tags_as_cloud($order = 'alpha', $tagsAreLinked = true, $item=null, $limit=null)
{
    if (!$item) {
        $item = get_current_item();
    }
    $tags = get_tags(array('sort'=>$order, 'record'=>$item), $limit);
    $urlToLinkTo = ($tagsAreLinked) ? uri('items/browse/tag/') : null;
    return tag_cloud($tags, $urlToLinkTo);
}

Now reads

function item_tags_as_cloud($order = 'alpha', $tagsAreLinked = true, $item=null, $limit=null)
{
    if (!$item) {
        $item = get_current_item();
    }
    $tags = get_tags(array('sort'=>$order, 'record'=>$item), $limit);
    $urlToLinkTo = ($tagsAreLinked) ? uri('items/browse?=tags') : null;
    return tag_cloud($tags, $urlToLinkTo);
}

Now everything is working, and the html_escape function is returning the tag names.

Thank you for the help!