Beginner theming questions

46 views
Skip to first unread message

Bridger Dyson-Smith

unread,
Nov 15, 2010, 12:28:34 PM11/15/10
to omek...@googlegroups.com
Hi all - 
many thanks for reading and your thoughts. If these questions should be addressed to the omeka forums, please let me know and I'll post them there. At this point, I'm more interested in trying to get a handle on how Omeka (and the Zend Framework) behaves rather than specific code examples -- I'll probably need those later :).

I would like to change the way Omeka is displaying some of it's information:
1) When browsing items in a collection, I'd like to display the collection name in the site-title div instead of the Omeka instance name. Is the best place to effect this change in the themes/theme-name/common/header.php file?

2) I'm not quite sure what to call this in the Omeka-PHP paradigm, but do I need to be concerned with fall-back or *.php file precedence? In other words, are display changes best made in the themes/theme-name directory as opposed to the files in admin/themes/default/?

I must confess that I'm new to PHP, so I've probably overlooked something glaringly obvious. 
Thanks again!
Cheers,
Bridger

John Flatness

unread,
Nov 15, 2010, 3:16:56 PM11/15/10
to omek...@googlegroups.com
You seem to be mostly on the right track.

You're correct that the site-title div is handled in the common/header.php file.  You could simply edit this file and add a conditional that checks if you're browsing by collection, but this isn't the easiest way.  Instead of editing the theme header, you could write a simple plugin that filters the site title.

If you haven't seen this yet, there's some information about Omeka's plugin API at http://omeka.org/codex/Plugin_API .  Moving something like this to a plugin would allow it to work across all themes, and the less tweaking you do to a customized theme, the easier it will be to upgrade. As far as your specific scenario is concerned, a plugin could use the filter "display_settings_site_title" to replace the site title with the collection name when you're browsing a collection, and this would work without you having to edit the common/header.php file.

The example at http://omeka.org/codex/Plugin_Use_Cases/Add_Navigation_to_the_Admin_Theme is very similar to what you'd end up writing for something like this, only using a different filter.

As to your second point, fallback isn't currently a major issue (though themes may use this feature more often soon).  The themes/theme-name directories and the admin/themes/default directories are entirely separate.  The admin one only affects the admin side, the themes/theme-name ones only affect the public side.  There is, however, one more place that Omeka will look for theme files for both the admin and public sides of the side.  The application/views/scripts directory is the fallback for all themes, Omeka will try to load a file from there if it can't find it in the current theme.

The practical upshot of all this is that display changes should be made in the themes/theme-name directory.  Changes in the admin directory won't affect what your users see, and changes to application/views/scripts will likely be overriden by the files in themes/theme-name.

-John

--
You received this message because you are subscribed to the Google Groups "Omeka Dev" group.
To post to this group, send email to omek...@googlegroups.com.
To unsubscribe from this group, send email to omeka-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/omeka-dev?hl=en.

Bridger Dyson-Smith

unread,
Nov 16, 2010, 12:09:16 PM11/16/10
to omek...@googlegroups.com
John - 
thanks for the reply! 

I'll take a look at plugins. I hadn't considered the filtering aspect of plugins for Omeka - this could potentially make things significantly easier for us.
Cheers,
Bridger

Bridger Dyson-Smith

unread,
Nov 22, 2010, 4:12:19 PM11/22/10
to omek...@googlegroups.com
Hello all - 

thanks again to John for the suggestion to investigate a plugin. After some reading and testing (quickly followed by more and more reading...), I think I have a rough idea of what I need to do with a filtering plugin to make a simple collection switch. 

While I think I have a decently rough grasp of what to do with a switch(), I'm not quite sure which filters (or hooks?) I need to use. Any suggestions or thoughts would be most appreciated.

Cheers,
Bridger

add_plugin_hook('public_theme_header', 'collection_filter_public_theme_header');
function collection_filter_public_theme_header()
{
$collection = get_collection_by_id($_GET['id']))
switch ($collection) {
case 1:
$collection_title = 'Early Images of Egypt';
break;
case 2:
$collection_title = 'Copeland Railroadiana Collection';
break;
default:
$collection_title = 'Omeka Instance';
break;
} return '$collection_title';
}

John Flatness

unread,
Nov 23, 2010, 1:36:25 PM11/23/10
to omek...@googlegroups.com
Hi,

I think the reason why you were having trouble with the filter I suggested is that I let an extra "s" creep in there.  The correct filter you want to use is "display_setting_site_title" (note "setting", not "settings").

There's now some documentation about the "display_setting" filters at http://omeka.org/codex/Plugin_API/Filter/display_setting_* , that includes a simple example.

-John

Bridger Dyson-Smith

unread,
Nov 29, 2010, 10:54:17 AM11/29/10
to omek...@googlegroups.com
Hi all - 

With significant help from a coworker I've reached a point where I have a partially functional dynamic titling display. I'm uncertain where to take it next. While this is mostly attributable to my lack of PHP, I'm also not quite sure which functions need to be called. Any suggestions, thoughts, and especially corrections would be most welcome!

Thanks,
Bridger

With the following code, I have dynamic titles at the show collection level ( i.e., when my URL looks something like: localhost/collections/show/1 ) but I lose titles on all other pages ( e.g. localhost, localhost/items/show/128, localhost/collections, localhost/items/advanced-search, etc ).

add_filter('display_setting_site_title', 'collection_filter_site_title');
function collection_filter_site_title()
{
$collectionName = "Instance One";
if (!$collectionObj) {
    $collectionObj = get_current_collection();
    $collectionName = collection ('name', array(), $collectionObj);
}
elseif (item_belongs_to_collection()) {
    $collectionObj = get_collection_for_item();
    $collectionName = collection ('name', array(), $collectionObj);
}
return $collectionName;

John Flatness

unread,
Nov 29, 2010, 11:40:03 AM11/29/10
to omek...@googlegroups.com
What's probably causing your problem is your first "if" line.

When your function gets called, the variable $collectionObj won't exist to begin with, and that first "if" section will always be true.  So, no matter what page you're on, your code uses get_current_collection().  Since that only works on collection pages, you see your correct titles there, and blank titles everywhere else.

One important thing about filters is that they can take an argument of the value that's being filtered.  In this case, that means that your filter_site_title function can have the site's actual title (as set in Site Settings) passed into it, so you don't need to manually specify "Instance One" like you have below.

Here's a simplified function that should return the collection name if you're on a collection page, and the site title on all other pages:

add_filter('display_setting_site_title', 'collection_filter_site_title');
function collection_filter_site_title($siteTitle)
{
    $collectionObj = get_current_collection();

    if ($collectionObj) {
        $siteTitle = collection('name', array(), $collectionObj);
    }

    return $siteTitle;
}

This function doesn't include code that checks against a current item; you'd include code like that before the "if ($collectionObj) {" line.

-John

Bridger Dyson-Smith

unread,
Nov 30, 2010, 1:56:36 PM11/30/10
to omek...@googlegroups.com
John - 
thanks for the continued assistance. One last question and this topic should be finished (at least for the day).

Your suggestion is working wonderfully; we added an $item test to the plugin code and that is also working. We're not sure how to effect the change at the "view all items in a collection" level though - specifically when URL looks something like: localhost/items/browse?collection=1. We can't seem to catch the collection id number that's being passed. Which function are we missing here?

I'm thinking that the (!$collectionObj) is incorrect - but I'm also not certain if I'm actually dealing with a $collectionObj at this point, or something else. I've tried experimenting with the collection() function without any results. Any guidance or suggestions are greatly appreciated.

Cheers,
Bridger

<?php
// add filter
add_filter('display_setting_site_title', 'collection_filter_site_title');

// add function 
function collection_filter_site_title($siteTitle)
{
$collectionObj = get_current_collection();

        if ($item = __v()->item) {
$collectionObj = get_collection_for_item(get_item_by_id(item('id')));
}
// if (!$collectionObj) {
// $collectionObj = get_current_collection('name');
//
// }
if ($collectionObj) {
$siteTitle = collection('name', array(), $collectionObj);
}
return $siteTitle;
}
?>
Reply all
Reply to author
Forward
0 new messages