List all items in collection on collection show page

On the individual collection pages generated by collections/show.php, I'd like to list every item in the collection. The loop looks like this:

<?php while (loop_items_in_collection(5)): ?>
<?php echo link_to_item(item('Dublin Core', 'Title'), array('class'=>'permalink')); ?>
<?php echo item('Dublin Core', 'Description') ?>
<?php endwhile; ?>

It doesn't matter what value I put in loop_items_in_collection(); it always returns 10 items.

Can someone explain the syntax of loop_items_in_collection() for me?

Hi Lincoln,

Are you sure that loop_items_in_collection() isn't working properly for you? I just tested it on my server and it worked fine. Passing an integer to the function (in my case it was 3 items) I was able to limit the items being displayed. It should work similarly for you.

If you're looking to display all items in a collection, you'll need to display an arbitrarily high number. Pick 100 or 1000 or something. Note that if you choose 1000000 and have 1,000,000 items then it may slow down your connection -- that's why we try to deter it.

Let us know how it works out.



Thanks for the response. I figured that was how loop_items_in_collection() worked, so I tried passing it both large numbers and small numbers. No matter whether the value was 2 or 10000, collections/show always showed no more than 10 items in a collection.

I'm modifying the "Thanks Roy" theme, and I figured that I had messed something up, so I switched to the Berlin theme. In that theme I changed the value passed to loop_items_in_collection() and got the same result: no more than 10 items in a collection.

I looked and the function definition for loop_items_in_collection() and noticed that it referred to 'per_page', so I changed the settings in for "per page public" in the Omeka Admin to an arbitrarily high number. Still 10 items per collection.

In NewThemeFunctions.php, the function definition looks like this:
loop_items_in_collection($num = 10, $options = array())
I tried changing the default for $num to 10000, then tried passing loop_items_in_collection() no value. Still 10 items per collection.

I figured that I was making an amateur mistake somewhere, so I asked my local PHP guru for help. He looked at the function definitions for loop_items_in_collection() and for get_items(). He figured out that the default value for $limit in get_items() overrides the value passed to it by loop_items_in_collection(). His solution was to change the line in loop_items_in_collection() that reads

$items = get_items(array('collection'=>get_current_collection()->id, 'per_page'=>$num));

so that it reads

$items = get_items(array('collection'=>get_current_collection()->id),$num);

That solution works. I'm able to change the value passed to loop_items_in_collection() to a low number or a high number, and the function performs as expected.

Does that solution make sense? Is there a better way besides modifying the Omeka files?

Thanks for catching this. Looks like we've fixed this bug in the trunk already, albeit without knowing it existed.

I'm going to verify that this bug shows up on my copy of 0.10 and then add the fix to our repository.

Hi there,

I am sorry to restart this thread from a long time ago, but I was wondering if someone has a current solution for this issue?

On my collections/show pages, only 5 items from any given collection are displayed, and the user has to click on "items in the [Collection Name] Collection" to view all the items in the collection.

I went in to my collections/show.php file, but could not find the pieces of code referred to above. Does anyone have a current solution for getting Omeka to display more than five items in a collection on the collections/show page?



The thread is old enough that any code examples will be far out of date.

For the latest Omeka versions, unfortunately that calls for a change in the core files. In application/controllers/CollectionController.php, look for these lines around line 43:

public function showAction()
        $this->view->items = $this->_helper->db->getTable('Item')->findBy(
            array('collection' => $this->view->collection->id), is_admin_theme() ? 10 : 5);

The 5 is how many items to show on the show page. Change that number to however many you want.

Bear in mind that updates to Omeka will override that change, so you'll want to put a sticky-note on your monitor to remind you to remake the change when you do an update of Omeka.

That worked perfectly! Thank you very much for your help!

A possible alternative that doesn't require editing core is to display your collection metadata above your browse results for collection items (thanks to John for the idea). I did this like so (our collections only have titles & descriptions):

<?php parse_str($_SERVER['QUERY_STRING'], $queryarray); ?></p>
<p><?php if (array_key_exists('collection',$queryarray) && $queryarray['collection'] != ''): ?>
       $db = get_db();
       $collection = $db->getTable('Collection')->find($queryarray['collection']);
       $collectionTitle = strip_formatting(metadata($collection, array('Dublin Core', 'Title')));
      if ($collectionTitle == '') {
          $collectionTitle = __('[Untitled]');
<p>     <h1><?php echo $collectionTitle; ?></h1></p>
<p>      <?php if ($description = metadata($collection, array('Dublin Core', 'Description'),array('index' => 0))): ?>
          <?php echo $description; ?>
      <?php endif; ?>
      <?php if ($description = metadata($collection, array('Dublin Core', 'Description'),array('index' => 1))): ?>
          <?php echo $description; ?>
      <?php endif; ?>
<?php endif; ?>

There may be a more elegant way to do this, but it works! I then provide a link to the search results page in my navigation, excluding the collection page.

I suspect you could also remove the loop(items) portion of collections/show.php and write your own function to display items using get_records, which lets you define your own limit.

Thank you very much!