Forums » Display total number of Items for each Collection on Index

RSS feed for this topic

Info

  1. Hello. I've been able to use the 'total_items_in_collection' function to display on my Collections/Show the total number of Items in that particular Collection. And I have been able to use the 'total_items' function on my index.php to display the total number of Items in my entire Omeka project.

    How can I display the total number of Items in each (an array) Collection, or just a particular (singular) Collection on my index page? My PHP is rusty, and I've been playing with those 2 functions quite a bit, but keep throwing an error (something about a missing object) on my index page.

    Thank you, as always, for your great help!

  2. I imagine that the quickest way at it would be to mimic what the collections/browse.php page does to loop through the collections, then apply the same tricks you used on the collections/show page for each collection.

    Many Omeka pages make use of a pattern that looks like:

    <?php while(loop_collections()): ?>
    <div class='collection'>
    <!-- echo out your info for each individual collection here -->
    </div>
    <?php endwhile; ?>

    The loop_collections (or loop_items, etc.) pattern keeps track of what the current collection being displayed is, and many of the other function make use of the get_current_collection() function. Without using that pattern (or calling set_current_collection($collection), total_items_in_collection() will look for the current collection but find nothing -- your missing object error.

    So, the most straightforward thing to try with your array of Collections is probably something like:

    <?php set_collections_for_loop($yourArrayOfCollections); ?>
    <?php while(loop_collections()): ?>
    <div class='collection'>
    <!-- echo out your info for each individual collection here -->
    </div>
    <?php endwhile; ?>

    Then, within that div where you echo things out, the things that you did on the collections/show page should work as expected.

The forums are closed to new posts. To post new topics and read the latest discussions, please see the new forums.