Plugin Suggestion: Item Counter

Hello,

It might be cool/useful to see a counter that displays # of items in the archive, either on the homepage or a collection.

I am wondering if it is possible to develop a plugin/widget to display the # of items in Omeka's database somewhere on the site (for example as an on/off toggle in the footer, as well as a chunk of code that can be automatically generated and copy/pasted into a custom page (such as a page created with Simple Pages plugin) or a field (like a shortcode that can be dropped into a collection description box). That way returning or new visitors could get a quick sense about the volume of content stored in the archive. (Similar to when libaries often mention that they have an X million books.)

(I did a quick search and didn't see this mentioned earlier; pardon for any overlap.)

Thoughts? Or suggestions for a quick (and simple!) hack? (at a level of a casual/non-techie user...)

Thanks in advance.

The basics would be pretty easy. This function would get the count:

function count_items($collection = null)
{
    if($collection) {
	if(is_numeric($collection)) {
	    $collectionId = $collection;
	} else {
	    $collectionId = $collection->id;
	}
	$count = get_db()->getTable('Item')->count(array('collection'=>$collectionId));
    } else {
        $count = get_db()->getTable('Item')->count();
    }
    return $count;
}

A simple plugin could make use of any of a number of hooks we have available to add content to a page.

This would be a great first plugin for someone learning Omeka to try. See our best practices to get started

Thanks! Not sure I am up for plugin making, this may be handled more effectively by someone who knows what they are doing. I am probably somewhere at the level where I need to be told pretty explicitly: "copy this function, now paste it HERE in file named xyz.php, now update this other page like this to call the function, now re-ftp it and see if anything shows up."

But I will tinker with the function and see if I can get it to show up. If there are Omeka installs out there that put this in place, please share a link and what else might be helpful to know to get it to work!

Best,
A

If you're just looking to show the total number of items in your Omeka database, Omeka already has a function for that: total_items. We use it on the admin-side dashboard, but you could use it on your public theme, too.

<?php echo total_items(); ?>

That's exactly what I needed! And I've just discovered the Functions page ;) Thanks.