Add custom class to Views list based on count.
// For theming purposes we want to add a "clear" class every certain number
// of items.
define('CII_THEME_MEMBERS_LOGOS_CLEAR_EVERY', 6);
define('CII_THEME_MEMBERS_ADVISORYBOARD_CLEAR_EVERY', 4);
/**
* Preprocess function for views list.
*
* You can figure out how this should be named by enabling devel_themer and clicking
* on items on the webpage.
*
* Once you have the function, you can examine $vars by inserting dpm($vars) in the
* function, and examining the output; then create your logic.
*
* @param &$vars
* Preprocess variables.
*
* See also "Setting up variables for use in a template (preprocess and process
* functions)", on Drupal.org, https://www.drupal.org/node/223430
*/
function cii_preprocess_views_view_list(&$vars) {
if ($vars['view']->name == 'members') {
// Member logos.
if ($vars['view']->current_display == 'block_2') {
foreach ($vars['classes_array'] as $index => $classes) {
if ($index % CII_THEME_MEMBERS_LOGOS_CLEAR_EVERY == 0) {
$vars['classes_array'][$index] .= ' wide';
}
}
}
// Advisory Board - Featured.
if ($vars['view']->current_display == 'block_5') {
foreach ($vars['classes_array'] as $index => $classes) {
if ($index % CII_THEME_MEMBERS_ADVISORYBOARD_CLEAR_EVERY == 0) {
$vars['classes_array'][$index] .= ' wide';
}
}
}
}
}