Forums » List all items in collection on collection show page

RSS feed for this topic

Info

  1. 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?

  2. 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.

    Dave

  3. Dave,

    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?

  4. 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.

Reply

You must log in to post.