Views theme template functions instead of template files
Normally when overriding a views template it's a case of create a file like views-view-unformatted--featured.tpl.php. But this is actually a performance hit when it could be picked up as a theme template function instead.
The above function would be
function MYTHEME_views_view_unformatted__featured($view, $grouping, $rows) { }
I should probably just have made this into my own views output type, but this is an example of using the unformatted row output to make a non-tables based grid since well, tables are evil.
function MYMODULE_views_view_unformatted__featured($view, $grouping, $rows) { $per_row = 5; $count = 1; $row_count = 0; $per_row_count = 1; $output = ''; $max_rows = $view->row_index + 1; $max_row_rows = floor($max_rows / $per_row) + (($max_rows % $per_row) > 0 ? 1 : 0); foreach ($rows as $id => $row) { if ($per_row_count == 1) { $row_count++; $class = array( 'views-wrap-row', 'views-wrap-row-' . $row_count, ); if ($row_count % 2 == 0) { $class[] = 'views-wrap-row-even'; } else { $class[] = 'views-wrap-row-odd'; } if ($row_count == 1) { $class[] = 'views-wrap-row-first'; } if ($row_count == $max_row_rows) { $class[] = 'views-wrap-row-last'; } $output .= '<div class="' . implode(' ', $class) . '">'; } $class = array('views-row'); if ($count == 1) { $class[] = 'views-row-first'; } if ($count == $max_rows) { $class[] = 'views-row-last'; } if ($per_row_count == 1) { $class[] = 'views-row-row-first'; } if ($per_row_count == $per_row) { $class[] = 'views-row-row-last'; } if ($count % 2 == 0) { $class[] = 'views-row-even'; } else { $class[] = 'views-row-odd'; } if ($per_row_count % 2 == 0) { $class[] = 'views-row-row-even'; } else { $class[] = 'views-row-row-odd'; } $output .= '<div class="' . implode(' ', $class) . '">' . $row . '</div>'; $count++; $per_row_count++; if ($per_row_count > $per_row) { $output .= '<div class="clearboth"> </div></div>'; $per_row_count = 1; } } if ($per_row_count > 1 && $per_row_count < $per_row) { $output .= '<div class="clearboth"> </div></div>'; } $output .= '<div class="clearboth"> </div>'; return $output; }
The clearboth is a common method I use for clearing both the floats in the render model. It's a simple CSS class with simply "clear: both;" in it.
.clearboth { clear: both; }