it seems you need to know value of node which is referring the current node.
I am assuming machine name for the refernce field you have on event content type as "field_event_gallery"
In your custom module or template.php
// function to get backrefernce value.
function mymodulename_get_back_refernce_value($current_nid) {
$nids = array();
$results = db_select('field_data_field_event_gallery','n')
->fields('n',array('entity_id'))
->condition('field_event_gallery_nid',$current_nid)
->execute()
->fetchAll();
if(is_array($results) && count($results) > 0) {
foreach($results as $result) {
$nids[] = $result->entity_id
}
}
return $nids;
}
Now in your theme template.php use template_preprocess_node(),something like below
function MYTHEME_preprocess_node(&$variables) {
$node = $variables['node'];
if ($node->type == 'gallery') {
//get referring nids
$referring_nids = mymodulename_get_back_refernce_value($variables['node']->nid);
if(count($referring_nids) > 0) {
foreach($referring_nids as $referring_nid) {
$referring_node = node_load($referring_nid);
$variables['parent_event_link'][$referring_nid] = l(t('View parent event: @event_title', array('@event_title' => $referring_node->title)), 'node/' . $referring_nid);
}
}
}
finally in your template loop through $variables['parent_event_link'] and print it.
My codes are not tested, you have to debug to make them workign for you