Linking to Exhibit from Item Page using custom.php in a theme

I am running Omeka v2.4.1 and Exhibit Builder v3.3.1

I am trying to establish a link back to and exhibit page from an item which is already linked to from the exhibit page.

I have found the following forum page:

http://omeka.org/forums-legacy/topic/linking-to-exhibit-from-item-page-1

I have the following in /themes/berlin/custom.php

<?php function link_to_related_exhibits($item) { $db = get_db(); $select = " SELECT e.* FROM {$db->prefix}exhibits AS e INNER JOIN {$db->prefix}exhibit_pages AS ep on ep.exhibit_id = e.id INNER JOIN {$db->prefix}exhibit_page_blocks AS epb ON epb.page_id = ep.id INNER JOIN {$db->prefix}exhibit_block_attachments AS epba ON epba.block_id = epb.id WHERE epba.item_id = ?"; $exhibits = $db->getTable("Exhibit")->fetchObjects($select,array($item->id)); if(!empty($exhibits)) { echo '

Related Exhibits

'; foreach($exhibits as $exhibit) { echo '

'.$exhibit->title.'

'; } } } I am not getting errors, but no links appears on my item page. I'm wondering if I could get some assistance with figuring out how to get the links to come up. Thx. --Eric

You didn’t specify, so let’s cover an obvious problem area:

You said you but the link_to_related_exhibits function into the custom.php file, but that just defines the function. Have you added a call to that function to your theme’s items/show.php?

Yes. Here is the call I have in there right now.

<?php echo link_to_related_exhibits('item'); ?>

Thx!

–Eric

Okay that’s likely the problem. Try

<?php link_to_related_exhibits($item); ?>

It’s the change from 'item' to $item that’s really relevant.

This did the trick. However, I now have another issue. The link being generated looks like:

https://ukscrc001.net/gn/items/show/exhibits/show/crosby-brittenum

I can’t seem to get the ‘items/show/’ to not be a part of the URL. I guess this has something to do with the current page from which the link is being generated? Is there an easy way to adjust the link in the function? Here’s what that looks like now:

<?php
function link_to_related_exhibits($item) {

    $db = get_db();

    $select = "
    SELECT e.* FROM {$db->prefix}exhibits AS e
    INNER JOIN {$db->prefix}exhibit_pages AS ep on ep.exhibit_id = e.id
    INNER JOIN {$db->prefix}exhibit_page_blocks AS epb ON epb.page_id = ep.id
    INNER JOIN {$db->prefix}exhibit_block_attachments AS epba ON epba.block_id = epb.id
    WHERE epba.item_id = ?";

$exhibits = $db->getTable("Exhibit")->fetchObjects($select,array($item->id));

if(!empty($exhibits)) {
    foreach($exhibits as $exhibit) {
echo '<div style="float:right;"><h3><a href="exhibits/show/'.$exhibit->slug.'">Biography</a></h3></div>';
    }
}
}

Thanks so much for the help! Getting very close to success with this!

–Eric

Hey. I resolved this issue. Here is what the code looks like now, and it works.

<?php
function link_to_related_exhibits($item) {

    $db = get_db();

    $select = "
    SELECT e.* FROM {$db->prefix}exhibits AS e
    INNER JOIN {$db->prefix}exhibit_pages AS ep on ep.exhibit_id = e.id
    INNER JOIN {$db->prefix}exhibit_page_blocks AS epb ON epb.page_id = ep.id
    INNER JOIN {$db->prefix}exhibit_block_attachments AS epba ON epba.block_id = epb.id
    WHERE epba.item_id = ?";

$exhibits = $db->getTable("Exhibit")->fetchObjects($select,array($item->id));

if(!empty($exhibits)) {
    foreach($exhibits as $exhibit) {
echo '<div style="float:right;"><h3><a href="'.exhibit_builder_exhibit_uri($exhibit).'">Biography</a></h3></div>';
    }
}
}

Thx!!

–Eric

Happy to hear it.

The problem with your previous version was the lack of the leading slash in the link text, but you’d have had to adjust it for your actual site’s location as well. The solution you went with, using the actual helper for generating the URL, is much better.

I am running Omeka 2.5 and Exhibit Builder 3.3.3. I am using the theme “Seasons” for both the main site and also for the exhibits I’m creating. Can I copy and paste the same code offered above into a custom.php file in /themes/season/ to create a link between my items and the exhibits in which they appear? Or do I need to edit other files in order to make sure my item pages know that they should be referring to the custom.php page? (Very much a novice with all of this.)

Hey,

I’m trying to front-end an omeka 2.3 with exhibit builder 3.2, theme Thank’s Roy. I’ve paste Eweig’s code on my theme/default/functions.php (which is called by customs.php). I have called it with <?php echo link_to_related_exhibits(); ?> on theme/default/items/show.php

But I get the following error :

Warning: Missing argument 1 for link_to_related_exhibits(), called in /Applications/MAMP/htdocs/musea/themes/default/items/show.php on line 19 and defined in /Applications/MAMP/htdocs/musea/themes/default/functions.php on line 368

Notice: Undefined variable: item in /Applications/MAMP/htdocs/musea/themes/default/functions.php on line 379

Notice: Trying to get property of non-object in /Applications/MAMP/htdocs/musea/themes/default/functions.php on line 379

I think I’m almost there. I would really much appreciate anyhelp you can give me.

Here is the code I pasted :

function link_to_related_exhibits($item) {

    $db = get_db();

    $select = "
    SELECT e.* FROM {$db->prefix}exhibits AS e
    INNER JOIN {$db->prefix}exhibit_pages AS ep on ep.exhibit_id = e.id
    INNER JOIN {$db->prefix}exhibit_page_blocks AS epb ON epb.page_id = ep.id
    INNER JOIN {$db->prefix}exhibit_block_attachments AS epba ON epba.block_id = epb.id
    WHERE epba.item_id = ?";

$exhibits = $db->getTable("Exhibit")->fetchObjects($select,array($item->id));

if(!empty($exhibits)) {
    foreach($exhibits as $exhibit) {
echo '<div style="float:right;"><h3><a href="'.exhibit_builder_exhibit_uri($exhibit).'">Biography</a></h3></div>';
    }
}
}

Do you think it has anything to do with the MAMP configuration and that it should work fine on a real server application?

The error messages suggest that $item isn’t working as expected, and just being null when you pass it in to link_to_related_exhibits().

Not entirely sure, but you might try something like this before calling link_to_related_exhibits():

$item = get_record('item');

I haven’t tried it, but ‘item’ might really be ‘Item’ or ‘Items’ or ‘items’. (I never remember the precise form that will work. But, I suspect one of those might help.

thanks Patrick !
I’m not sure where to put it thought (I’m really not a php developper) ?

In the function or in the show.php before calling link_etc. like, :

<?php $item = get_record('item'); echo link_to_related_exhibits(); ?>

that doesn’t work. It’s strange because this variable is used in many other functions.

If you see where I’m wrong, do not hesitate to tel me … (I’m going to try the same on a real serveur, in case the pb is in the MAMP configuration).

Still haven’t tried it directly, but I’d say that wherever you use your link_to_related_exhibits($item), put the $item = get_record('item'); at the very top of the theme page. Then it should be available as a parameter to pass in to link_to_related_exhibits($item). Make sure you keep the variable being passed in.