Created
January 26, 2011 19:35
-
-
Save jeremyboggs/797270 to your computer and use it in GitHub Desktop.
A helper function for Omeka to retrieve any number of random featured items. Include this function in your Omeka theme's custom.php file, and use wherever you'd like to get some random featur
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Custom function to retrieve any number of random featured items. | |
* | |
* @param int $num The number of random featured items to return | |
* @param boolean $withImage Whether to return items with derivative images. True by default. | |
* @return array An array of Omeka Item objects. | |
*/ | |
function custom_get_random_featured_items($num = '10', $withImage = true) | |
{ | |
// Get the database. | |
$db = get_db(); | |
// Get the Item table. | |
$table = $db->getTable('Item'); | |
// Build the select query. | |
$select = $table->getSelect(); | |
$select->from(array(), 'RAND() as rand'); | |
$select->where('i.featured = 1'); | |
$select->order('rand DESC'); | |
$select->limit($num); | |
// If we only want items with derivative image files, join the File table. | |
if ($withImage) { | |
$select->joinLeft(array('f'=>"$db->File"), 'f.item_id = i.id', array()); | |
$select->where('f.has_derivative_image = 1'); | |
} | |
// Fetch some items with our select. | |
$items = $table->fetchObjects($select); | |
return $items; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment