total_items_in_collection() causes fatal error

Hi Omeka,

I'm working on a theme and had some trouble with one of your built-in PHP functions. I'm not at all experienced with PHP so that's probably part of the problem. I tried to cut and paste the example from your Theme API page:

and I get the following error:

Fatal error: Call to a member function totalItems() on a non-object in /home/crymble/ on line 291

As far as I understand, this is supposed to show how many items I have in my collection.

fyi, the exact line of code I put into my theme is:

<?php echo 'Total Items:'. total_items_in_collection(); ?>

It looks like there is no current collection defined. What page in your theme are you trying to use the function?

Hey Will,

I was trying to use it on the "Browse Items" page. Maybe I'm misinterpreting what it's supposed to do.

I was under the impression I could use that to say how many items I have on the browse page so I could set up a "Showing items 1 - 10 of X" type thing.

Is this for something else? I do have 9 items in my database for testing purposes, so it's not totally empty.


You normally use a total_items_in_collection() on a collections page. It does not mean, the total number of items in your archive.

To do a showing items (1 - 10 of X) type of thing, you should look at the pagination_links() helper function located in application/helpers/LinkFunctions.php . By default this function uses the application/views/scripts/common/pagination_control.php file as its partial view. You could copy this view into the commons directory of your theme and edit it to overide the default view. If you wanted to keep the old pagination on some pages, but not for others, you could rename the file you copied to your themes directory, say to custom_pagination_control.php, and then call the pagination_links function with the location of the new custom pagination view.

So for example, you call something like in your browse items page:

$partialFile = 'common' . DIRECTORY_SEPARATOR . 'custom_pagination_control.php';
pagination_links(array('partial_file'=> $partialFile));

Let me know if this helps.

Thanks, I'll try that.

I am trying to add a similar look to the pagination_links, so that instead of the word "Last", I get the number of the last page. I've copied the pagination_control.php to my theme's common directory. I've replaced:

<a href="<?php echo html_escape($this->url(array('page' => $this->last), null, $_GET)); ?>">"Last"</a>


<a href="<?php echo html_escape($this->url(array('page' => $this->last), null, $_GET)); ?>">
<?php $last=(total_results())/10;
echo ceil($last) ?></a>

It seems to work. If I display more records per browse page, I'll have to change the 10 to match the items displayed per page.

In pagination_control, $this->last is always the number of the last page.

You can see it's what gets used to build the actual link to the last page, which has to have the page's number. Any of the variables listed here are available in the same way.

Thanks. I figured there was a better way to do that.