How to display title of referenced views?
petrelharp - September 11, 2009 - 21:34
| Project: | View Reference |
| Version: | 6.x-2.21 |
| Component: | User interface |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
I'm trying to display the title of certain views at the top of where they are displayed using viewreference. I've looked around a lot, but haven't come up with a way to do this. Currently, I can't seem to get the title of any view displayed through viewreference. Any help would be appreciated!
thanks!

#1
Do you want just the title ? This can be done through the 'display fields' section in CCK.
If you want the title and the executed view you may have to override the theme function as I don't think there is a 'full' formatter atm.
<?php
/**
* Theme function for 'default' viewreference field formatter.
*
*/
function theme_viewreference_formatter_default($element) {
$output = '';
if (!empty($element['#item']['view_id']) && is_numeric($element['#item']['view_id'])) {
$view = db_fetch_object(db_query("SELECT name, position FROM {viewreference} WHERE view_id = '%d'", $element['#item']['view_id']));
$args = viewreference_get_element_args($element);
$view_object = views_get_view($view->name);
$title = $view_object->get_title() ? $view_object->get_title() : $view->title;
$output .= '<h3 class="title viewsreference-title">'. check_plain($view->title) .'</h3>';
$output .= $view_object->preview($view->position, $args);
}
return $output;
}
?>
#2
Great! Thanks a ton! I do want the title along with the full view, and couldn't figure out the right place to do that. It seems like that'd be a good thing to have a checkbox to do, somewhere. Perhaps I'll try to figure out how to add that option.
There is just one minor correction to the code, fixed below -- it should be
check_plain($title), notcheck_plain($view->title:<?php
/**
* Theme function for 'default' viewreference field formatter.
*
*/
function theme_viewreference_formatter_default($element) {
$output = '';
if (!empty($element['#item']['view_id']) && is_numeric($element['#item']['view_id'])) {
$view = db_fetch_object(db_query("SELECT name, position FROM {viewreference} WHERE view_id = '%d'", $element['#item']['view_id']));
$args = viewreference_get_element_args($element);
$view_object = views_get_view($view->name);
$title = $view_object->get_title() ? $view_object->get_title() : $view->title;
$output .= '<h3 class="title viewsreference-title">'. check_plain($title) .'</h3>';
$output .= $view_object->preview($view->position, $args);
}
return $output;
}
?>
#3
i'll put this into the module so it won't be an issue for others in the future :P
#4
Rad. =)
#5
#6
Automatically closed -- issue fixed for 2 weeks with no activity.