Functions/get collection for item

This page is outdated

The information on this page concerns an old or obsolete version of Omeka. If you are using a more recent version, instead see get_collection_for_item on Omeka's Read the Docs.

Description

The get_collection_for_item() returns the Collection object for a specified item, and retrieves the current item object by default. This is meant to be a simple facade for access to the Collection record, and is used by link_to_collection_for_item() to generate a link to the current item's collection.

Usage

<?php echo get_collection_for_item($item=null); ?>

Arguments

  • $item (object) or null (default). If null, the current item in the loop is used.

Examples

Printing the Name of a Collection

The following example works on an items/show/ page. Retrieving the item's collection, the name of the collection is printed on the screen.

<?php
 
   $Collection = get_collection_for_item();
   echo $Collection->name;
 
?>

The name of the collection is available via the Collection database model. Similar code could be used to display both the name of a collection, and its description on an items/show/ page.

<?php
 
   if ($Collection = get_collection_for_item()) {
      echo '<h1>' . $Collection->name . '</h1>';
      echo '<p>' . $Collection->description . '</p>';
   } else {
      echo '<p>This item is not in a collection.</p>';
   } 
 
?>