Last updated November 25, 2008. Created by psynaptic on October 29, 2008.
Log in to edit this page.
This function sets up template files for list views e.g. views-[view_name].tpl.php where name is the name of your view. It was created to be as portable as possible between projects - just this one function needs to be copied and you can create templates for all your list views without needing to use views theme wizard to create separate functions for each view.
Warning: When using this function you will not see any output for list views until you create your views-[view_name].tpl.php file and add some print statements.
Sometimes it's better to have the output from a list view without the list markup. If you have a list view you don't want formatted in a list then just enter the name of the view in the $barebone_views array.
<?php
function phptemplate_views_view_list($view, $nodes, $type) {
$barebone_views = array();
$fields = _views_get_fields();
$taken = array();
// Set up the fields in nicely named chunks.
foreach ($view->field as $id => $field) {
$field_name = $field['field'];
if (isset($taken[$field_name])) {
$field_name = $field['queryname'];
}
$taken[$field_name] = true;
$field_names[$id] = $field_name;
}
// Set up some variables that won't change.
$base_vars = array(
'view' => $view,
'view_type' => $type,
);
foreach ($nodes as $i => $node) {
$vars = $base_vars;
$vars['node'] = $node;
$vars['count'] = $i;
$vars['stripe'] = $i % 2 ? 'even' : 'odd';
$vars['first'] = $i % 4 ? '' : ' first';
foreach ($view->field as $id => $field) {
$name = $field_names[$id];
$vars[$name] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
if (isset($field['label'])) {
$vars[$name . '_label'] = $field['label'];
}
}
$items[] = _phptemplate_callback('views-'. $view->name, $vars);
}
if ($items) {
if (isset($barebone_views[0][$view->name])) {
foreach ($items as $field) {
$output .= $field;
}
return $output;
}
else {
return theme('item_list', $items);
}
}
}
?>