Display tags on collections/show/?

My clients are unhappy that tags do not display on items listed in a collection (like they display on the Browse Items page).

I’m talking about /collections/show/1 for example. No tags display there and they’re currently being used to show the year of an item because Omeka is incapable of organizing by DC:date without extra code.

Is there an easy way to show tags on the collections show page? Is this theme-specific? We are using Seasons but this is NOT permanent.

What’s displayed or not displayed for the items listed on a collection’s show page is totally controlled by the theme.

Omeka’s default collections show view is located at application/views/scripts/collections/show.php, and you can copy that to “collections/show.php” in your theme and edit it there. (Many themes, including Seasons, don’t contain their own copy of the collections show view by default). You can print tags or any other data about the item in there.

Thank you, that worked. Since I have you, is there a string in the documentation that prints just the DC date? That would be helpful to display, too.

Would it be from here? https://omeka.readthedocs.io/en/latest/Reference/libraries/globals/metadata.html

You display a single piece of metadata with the metadata() function.

So displaying the DC Date is

echo metadata('item', array('Dublin Core', 'Date'));

Thank you again. I know I’m swinging wildly off-topic now, but I was trying to convert that DC date to a more human-readable format for browse. Info from https://omeka.org/forums-legacy/topic/sorting-by-dublin-core-date-field/ didn’t work because I’m no PHP programmer, but I assume there’s some way to combine that into one echo?

What’s the non-readable format you have the date in by default? Assuming it’s something relatively standard, it should be possible to convert that to whatever “nicer” format you’re looking for, yes.

I’ve standardized every entry to YYYY-MM-DD, YYYY-MM, or YYYY when no other information is present. Month DD, YYYY is probably the most legible?

So, yes, you can convert those dates. PHP includes built-in functionality for parsing and formatting dates. For example, the following would take a date like “2021-01-01” and print it instead as “January 1, 2021”:

$dateValue = metadata('item', array('Dublin Core', 'Date'));
$dateObj = DateTime::createFromFormat('Y-m-d', $dateValue);
echo $dateObj->format('F j, Y');

The shorter format with only year-month specified would take different format strings ('Y-m' in the createFromFormat call and 'F Y' in the format call). One simple thing you could do is just check the length of the date string to decide what format you have: if a date is 10 characters long, it’s year-month-day, if it’s only 7 characters long then it’s year-month, and if it’s 4 characters long then it’s just a year (and in that case you don’t need to alter it for display at all).

1 Like

Ha, I tried my confused hand at combining what you gave me and the link I provided from the old forum (2011), but no dice. It doesn’t affect the output. Luckily doesn’t give an error, though…

    <div class="date"><p><strong>
            <?php $dateValue = metadata('item', array('Dublin Core', 'Date'));
            if ((strlen($dateValue)==10)&&(strstr($dateValue,'-'))){
             $dateObj = DateTime::createFromFormat('Y-m-d', $dateValue);
            echo $dateObj->format('F j, Y');}
            
            elseif ((strlen($dateValue)==7)&&(strstr($dateValue,'-'))){
             $dateObj = DateTime::createFromFormat('Y-m', $dateValue);
            echo $dateObj->format('F, Y');}
            
            else {echo $dateValue;}
            ?>
    </strong></p></div>

You’re saying you just get the as-is formatted date output from that?

I don’t immediately see a problem with what you have there… you might just want to echo the strlen output to see how many characters $dateValue actually is… It’s possible that you have additional spaces or something along those lines that’s affecting the count so its neither 10 nor 7.

Yep, it just shows as it was before, like it’s taking all results as the final else statement. But I’ve just counted and the string is 10 characters long for full dates. Maybe it’s because the system is generating the dates as a link? So there’s HTML with <a href … etc.? Then I’d probably need to only target the characters between < a > and </ a > somehow.

Example of final page output:

<div class="date">
<p><strong>
            <a href="/archive/items/browse?advanced%5B0%5D%5Belement_id%5D=40&advanced%5B0%5D%5Btype%5D=is+exactly&advanced%5B0%5D%5Bterms%5D=2004-03-02">2004-03-02</a>
</strong></p>
</div>

Yes, combining this with the SearchByMetadata plugin will be a problem.

You can do one of the following things:

  • disable SearchByMetadata for Date (possibly reasonable, if lots of individual dates really don’t have lots of matches)
  • disable filtering here, so the link won’t be created at this location (to do this, pass array( 'no_filter' => true) as a third argument to metadata() (this is probably the simplest option if you don’t need the link in this location)
  • do this filtering actually in a plugin also (you can filter values for display with a plugin; this is how SearchByMetadata works, and you can have yours alter the displayed date first, before the link is made)
  • parse the HTML so you can edit just the content of the link after it’s made (I wouldn’t really recomment this route generally, though in a simple case like this it would probably work)
1 Like

Thank you, had the chance to add the array argument and that was definitely easiest. The dates transform properly now!

This topic was automatically closed 250 days after the last reply. New replies are no longer allowed.