Re-naming DC Fields

I have read previous posts where the items/show.php file is edited to re-order the way Dublin Core fields are displayed, but how can I ender in a code that will display a different text for public view? An example would be to have "Description" display "Contents" or "Item Text" on the public site instead. Thanks!

The easiest way to do this is to call item() individually for each field, and add your own heading separately for each field, on your theme's items/show.php template, like so:

<h2>Contents</h2>
<?php echo item('Dublin Core', 'Description'); ?>

See the documentation page for item() for more details on its use.

Alternatively, you could copy the application/views/scripts/items/item-metadata.php file to your theme, and do a check for each field you'd want to change there. Omeka uses this partial template for formatting the list of element sets and values generated by default. You could do this if you wanted to keep the order Omeka uses for displaying the fields. If you want to be more specific about the order, the previous method would work best.

Hi,

I'm also trying to re-title the Dublin Core fields on my display. I'd like to change "Description" to "Header", "Relation" to "Further Reading", "Text" to "Primary Source Text" and delete a few extra headers that are showing up in my item display, ("Dublin Core", "Document Type Metadata", and "Files").

I'm guessing that the part of the code I need to alter in the show item file is this:

<h3>All Titles</h3>
<ul class="title-list">
<?php foreach ($titles as $title): ?>
<li class="item-title">
<?php echo $title; ?>

<?php endforeach; ?>

Can you show me exactly how the call item() would look in the context of the larger code? I don't want to delete anything I shouldn't!

Thank you!
Karen

This isn't actually the right spot to change the titles for your fields. There's a separate template file called item-metadata.php that you'd want to use. Assuming you're OK with the default order of how Omeka outputs your metadata fields, you'll want to copy application/views/scripts/items/item-metadata.php to themes/yourthemename/items/item-metadata.php and edit in your theme. (Omeka will use the template file in your theme first, so you're free to edit this file in your theme as you need.)

On line 4 of the item-metadata.php file, there's the following code:

$elementName = $info['elementName'];

This is where you'd want to check whether the element name is a certain value, and change it to what you want. A switch statement that checks for the current value of $elementName and redefines it to the values you want would probably work. You'd probably want to check too, if you're displaying Dublin Core too, so you don't replace non-DC headings that happen to have the same name. Something like this, added immediately after the previously mentioned line in item-metadata.php, should get you started:

if ($setName == 'Dublin Core') {
    switch($elementName) {
        // Check if $elementName is 'Description'
        case 'Description':
            $elementName = 'Header'; // Change value of $elementName to 'Header'
            break;

        // Check if $elementName is 'Relation'
        case 'Relation':
            $elementName = 'Further Reading'; // Change value to 'Further Reading'
            break;

        // Add more cases as appropriate.

        // Leave the default for headings you don't want to change.
        default:
            $elementName = $elementName;
    }
}

This example doesn't take care of all your titles, but does replace two of them, that you can copy for each of the titles you'd want to replace. If you want to do a lot of replacement, though, it might be more beneficial to move these checks to a function, added to your theme's custom.php file, and then call that function in your theme's item-metadata.php file in place of this switch statement.. That's up to you, but it might be better to do if you expect to change the DC titles in other parts of your Omeka theme.

Thank you so much! I will give it a try and see how it goes.

Hi Jeremy,

I think I'm missing one small piece of the code, I'm getting an error that reads: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/kab233/nineteenthcenturydisability.org/themes/berlin/items/item-metadata.php on line 27

Can you suggest which bit I didn't put in. Below is the code that I changed in the file that you suggested, pretty much verbatim.

many thanks,
Karen

$elementName = $info['elementName'];
if ($setName == 'Dublin Core') {
switch($elementName) {
// Check if $elementName is 'Description'
case 'Description':
$elementName = 'Header'; // Change value of $elementName to 'Header'
break;

// Check if $elementName is 'Relation'
case 'Relation':
$elementName = 'Further Reading'; // Change value to 'Further Reading'
break;

// Check if $elementName is 'Text'
case 'Text':
$elementName = "Primary Source';

// Leave the default for headings you don't want to change.

default:
$elementName = $elementName;
}
}
$elementRecord = $info['element'];
if ($info['isShowable']): ?>

Not sure which line is #27. Could you post the all the code in your template in a pastebin and link to it here?

It could be that you need a break; after where you set 'Primary Source' for the Text field, like all the others. You'll need a break anytime you check for a case, except for default.

Thanks so much for the speedy reply. You were right about the break, but putting it in led to this error:

Parse error: syntax error, unexpected T_ENDFOREACH in /home/kab233/nineteenthcenturydisability.org/themes/berlin/items/item-metadata.php on line 46

<script src="http://pastebin.com/embed_js.php?i=RCnvCtqt"></script>

Thanks so much for all the help!
Karen

Remove line 27 entirely, the one with if ($setName == 'Dublin Core') {. You've got that check in there twice, but the second one (on line 27) isn't actually closed.

That removed the error message, but now my fields are still displaying under the default titles. Thanks again for your help!

Just did this, removing line 27 as I suggested, and it works fine for me. It swaps out the headings. Here's the entire file as a gist..

I uploaded the file, but it still didn't swap the names. I'm saving the file under themes/berlin/items/item-metadata.php--not sure what else could be wrong here. So sorry to be a pain and thanks again for all your help! Karen

Sorry to say I'm not sure what else to do. This works perfectly for me. I'm using Omeka 1.5.3, but this should work for a few versions back. You sure you have the berlin theme activated?

I just realized that I had re-ordered the Dublin Core fields in the dashboard. Per your earlier caution, could this be what's interfering with the script?

Yes--taking out the Dublin Core fields to display fixed the problem and the headers are now swapped! Sorry to be such a pain--I had forgotten that I had specified an order way back when I started the site!

Ah, OK. In that case, you'll need to create your own custom_show_item_metadata function in your theme. You can find the one Omeka uses by default in application/views/scripts/functions.php, around line 39. To make your changes, just copy this function to a functions.php file in your theme, and add that switch statement to this function.

Like this: https://gist.github.com/3994185

Hi Jeremy,

Thanks again for all the help. I restored the old item-metadata file to my theme, and added the function to a function.php file in my theme (under the path berlin/items/function.php). I'm now getting an error that prevents my site from displaying at all:

Parse error: syntax error, unexpected '<' in /home/kab233/nineteenthcenturydisability.org/application/views/scripts/functions.php on line 39

Here is a pastebin of the script.
<script src="http://pastebin.com/embed_js.php?i=anXt0XUD"></script>

Thanks again for all your time and help!
Karen

Hi Jeremy,

I'm sorry for posting so quickly. I think I have this halfway figured out. I had accidentally altered the original function.php file, and also put two custom_show_item_metadata functions into my script instead of altering the original one.

I now have this script under the path berlin/items/function.php.

<script src="http://pastebin.com/embed_js.php?i=MKp1CdPG"></script>

My only guess is that there's something wrong with the script or I've saved it in the wrong place in the theme.

Thanks so much for all your patience!
Karen

Ah, yeah, turns out this isn't possible exactly the way I had in mind. I've given you the runaround here, sorry! Here's what you'll need to do:

  1. rename the updated function to berlin_custom_item_metadata, or something else to your liking. (Can't have two functions named the same thing. Thought Omeka wouldn't load the core functions.php file if you had one in your theme, but I was mistaken.)
  2. Put that function (and only that function) in a custom.php file the root of your theme. So themes/berlin/custom.php, not themes/berlin/functions.php. Omeka loads custom.php automatically, not functions.php (long story). Make sure it's not in the items directory, as you've indicated in your previous posts.
  3. Update the line in themes/berlin/items/show.php that says <?php echo custom_show_item_metadata(); ?> and replace that with <?php echo berlin_show_item_metadata(); ?>, or whatever you named that function.
  4. Load your items/show view in your browser, and see if it displays correctly.

Thanks! That totally worked!

I'd also like to rename one of my metadata fields, "Text" to display as "Primary Source Text".

Is there a function I can add to do this?
thanks!
Karen

This custom show item metadata function, and the ability to specify their order in the theme configuration, currently only works with the Dublin Core element set, not the Item Type Metadata element set, of which 'Text' is part. You could add this, but it'd be a little more work.

Before we get into that, though, maybe we could back up a little bit, and instead of just adding features piecemeal, you could elaborate on what you'd like this to do. For example, do you want to change the labels for every field in the Dublin Core and Item Type Metadata, or just specific fields? Do you have a specific order in mind for these fields? (If so, specify that). It might be easier, after knowing more broadly want you want your items/show to do or behave, instead of tacking something else on.

(I believe changing the labels for specific fields, regardless of where they appear, should be easier in Omeka 2.0. One of the development team members should correct me here if I'm wrong, though.)

Thanks Jeremy. I thought I shouldn't ask too many questions at once, but I can see now doing it piecemeal is actually much more work for you!

The main things I'd like to do to customize the Berlin theme (beautiful theme by the way, thanks for developing it!) are:

1) Rename some of the Dublin Core and Item Type Metadata fields.

2) Get rid of the headings "Dublin Core" and "Item Type Metadata" which are showing up on my display items pages. Actually, if I could just do this I could stick with the name "Text" rather than "Primary Source Text" for this field.

3) Wrap the Item Type Metadata Text field in a nice light blue box, like the one that Featured items are popping up under.

I'm pretty much going for something like the one that the Children and Youth in History site developed using their theme. Eventually I might like to have nicer pages fronting "Browse Items" "Browse Collections" and "Browse Exhibits" as they do, but those three things are the basic changes I'd like to make for now to make the content on my site more transparent to users. They are mostly aimed at trying to clarify visually for users which part is the primary text (by renaming it, getting rid of distracting headlines and wrapping it in blue) and which part is the scholarly annotation.

If this is going to get much easier with Omeka 2.0, I can wait on some of these changes and concentrate on developing content for now.

Thanks again for all your help and patience!
Karen

If you don't care about the order of the fields displayed, it would probably be easier to go back to the first solution I proposed, which was to modify the item-metadata.php template. Then, you could just remove the headings that display the Element Set Name, and add a switch statement for the 'Item Type Metadata' element set.

My experience with Omeka is that relabeling AND reordering is one of the more common modifications people want to make. If you do care about the order of these, it would probably be better to modify that custom berlin_show_item_metadata function in our second solution to do what you'd need it to do. So, here's a gist that updates that function to loop through an internal array made of label => field associations:

https://gist.github.com/4024999

You'd just need to update that array to include the fields you want, with the labels you'd want, and the order in which you'd want them.

This also wraps each field with a <div> with a unique class value. So you could style the box for the primary source text field however you'd like (e.g. blue background) using that class value as a selector in your CSS.

I hope these examples illustrate how you can pretty much do whatever you'd like with your Omeka data, if you learn some basic PHP and understand how to get the data out of Omeka. Tinkering with themes in Omeka is a great way to learn PHP. (I learned PHP by modifying WordPress templates way before they even had themes.) There's also a documentation page on Learning PHP if you'd like resources for more general PHP stuff, though there are tons more up-to-date resources out there.

THANK YOU SO MUCH! The second option, the custom file, did it exactly, and I will now be able to rename and reorder without bothering you more! I will also definitely check out the PHP documentation.

One more question: I can't yet quite extrapolate from the php what the unique class value for each field is so that I can define it in the CSS.

If this is the line for the field I want to call up:
'Primary Source Text' => item('Item Type Metadata', 'Text', null, $item),

What would it be called in the CSS? I assume it's something to do with this line:
$html .= '<div class="field field-'. text_to_id($label) .'">'

I guessed "text-value" and "$text" to no avail.

Thanks again!
Karen

One more question: I can't yet quite extrapolate from the php what the unique class value for each field is so that I can define it in the CSS.

Forgot to include a note about that. That HTML snippet you quote is the place where this class gets generated. It wraps each field with a div that has a class attribute equal to 'field' and 'field-labelname' where 'labelname is a lower case, dashed version. E.g. 'field-primary-source-text'. The text_to_id function does that transformation. So, to style that field, you'd use something like:

.field-primary-source-text {
  /* Styles here...*/
}

Similarly for any other fields you want to add.

Its handy to also use tools available in your browser to read the HTML that gets output. I use Chrome, and it has some handy Developer tools you can use to inspect the page, including the HTML. Other browsers have similar features built in or available as plugins, so I'd encourage you to check those out. I use the Chrome tools quite regularly.

Hi please how to do the same things with 2.01 version?.
themes/berlin/items/item-metadata.php not present in 2.01.
Also i need to change order of fields in BERLIN CORE
Thank you

You can change the order of the fields in Settings > Element Sets.

The file that was previously called "items/item-metadata.php" was replaced by "common/record-metadata.php".

We are using Omeka 2.1.14. I attempted to implement the reordering/relabelling solution Jeremy proposed here: http://omeka.org/forums/topic/re-naming-dc-fields#post-14128

I am, however, getting an error when I view an item in the exhibit:
Fatal error: Call to undefined function item() in /var/www/html/project/themes/sellingsmoke/custom.php on line 22

(sellingsmoke being the theme assigned to this exhibit)

Line 22 in custom.php is as follows:
'Title' => item('Dublin Core', 'Title', null, $item),

Thanks in advance for any guidance you could provide.

The item() function was replaced with the more general metadata() function. So to get the title you would use:

metadata('item', array('Dublin Core', 'Title'));

Thank you, patrickmj!