featured collection

Hi,

I would like to use the featured collection function (display_random_featured_collection), but have it reference only some collections.

Would this require the creation of a new function? Or, is that discouraged? Is there another way to do this?

Thank you!
beth

Hi Beth,

When you say "only some collections," what do you mean specifically? More than one featured collection? Or a specific list of collections, regardless of whether it is featured? It's possible to do both of those, but the code would be different for each.

Creating a new function is actually encouraged, too! You can put any custom functions you want to use in your theme's custom.php file.

Hi,

What I would like to do is to randomly display featured collections from a specified list of featured collections.

More specifically, I am creating an "exhibit" for each of our member libraries. For the main page of each "exhibit", I would like to be able to display randomly selected collections from among that library's featured collections.

Does that make sense?

Thanks!
beth

What I would like to do is to randomly display featured collections from a specified list of featured collections.

What you'll need to do here is do a query that randomly gets any number of collections that are marked featured in the database. Here's a function I just wrote that should do this:

<?php

function get_random_featured_collections($num = 3)
{
    $db = get_db();
    $table = $db->getTable('Collection');
    $select = $table->getSelect()->where("c.featured = 1")->order('RAND()')->limit($num);
    $collections = $table->fetchObjects($select);
    return $collections;
}

?>

Add this to your custom.php file of your theme, and use this anywhere you want to get an array of random featured collections and display data for them. Here's a quick example I used to test this on my install's homepage:

<?php 

$collections = get_random_featured_collections(2);

foreach($collections as $collection) {
    echo $collection->id;
}

?>

Hope this helps!

HI Jeremy,

I'm not sure if I explained clearly what I want to get at here. I want to display random collections, but want to be able to specify which collections (rather than how many), should be included in the query.

For example, I think the following line needs to specify a range of collection ids, but I don't know the correct syntax. Something like this maybe:

$select = $table->getSelect()->where("c.featured = 1" and c.id in(21,23,24,29,30))->order('RAND()')->limit($num);

does that make sense?

Thanks again for your help!

Hi Jeremy,

I would like to use this function with exhibits pages. Should it work within the ExhibitBuilder plugin? I added the function to ExhibitFunction.php and added the code to my exhibit summary.php file. The rendered page does not display a collection, though, only a random(?) number. Not yet sure where the number is coming from.

thanks!
beth

Hi Beth,

Sorry for the delay in responding.

For your message six days ago, about picking random collections from a list of collection IDs, it would probably be easier to write a custom script that would just pick from that array of IDs using PHP's array_rand() function. You wouldn't even need to query the Omeka database, if you know the IDs before hand. something like this:

<?php

// Your array of collection IDs
$collectionIds = array('1','4','10','12'); 

// Lets get one random ID from that array
$randomCollectionId = array_rand($collectionIds, 1);

// This sets the current collection object, using Omeka's get_collection_by_id helper.
set_current_collection(get_collection_by_id($randomCollectionId[0]))

?>

You could put this anywhere in your theme, or in ExhibitBuilder themes/layouts.

Best,
Jeremy

Hi Jeremy,

I'm afraid I am just not getting this.

Wouldn't I also need to use part of the code for the "display_random_featured_collection" helper in order to display the title of and link to the selected collection?

I don't want to take up more of your time on this, since I realize it is not your intention to teach a PHP course here.

I'll have to keep working on this.

I appreciate your help.
beth