Just noticed the first and last classes are missing from the row, is there a way to add this in as <?php print $classes[$id]; ?> does not work.

Comments

theunraveler’s picture

Status: Active » Needs work

I would be happy to do this. Currently, however, I am working on an actual fix to get $classes actually outputting useful data. So once I solve that bigger issue, this issue should be fixed. I will report back when I've been able to work on it a bit more.

tadfisher’s picture

Hey, I fixed it.

Add to views_limit_grouping.views.inc:


function views_limit_grouping_views_plugins() {
  return array(
    'style' => array(
      'grouping_limit' => array(
...
        'theme file' => 'theme.inc',
...

In theme.inc (copied from template_preprocess_views_view_unformatted):


function template_preprocess_views_limit_grouping(&$vars) {
  $view     = $vars['view'];
  $rows     = $vars['rows'];

  $vars['classes'] = array();
  // Set up striping values.
  foreach ($rows as $id => $row) {
    $row_classes = array();
    $row_classes[] = 'views-row';
    $row_classes[] = 'views-row-' . ($id + 1);
    $row_classes[] = 'views-row-' . ($id % 2 ? 'even' : 'odd');
    if ($id == 0) {
      $row_classes[] = 'views-row-first';
    }
    if ($id == count($rows) -1) {
      $row_classes[] = 'views-row-last';
    }
    // Flatten the classes to a string for each row for the template file.
    $vars['classes'][$id] = implode(' ', $row_classes);
  }
}

theunraveler’s picture

Status: Needs work » Needs review

Awesome! I'll test this out and then commit it if it works. Thank you so much!

ndwilliams3’s picture

I also needed the classes for rows. No need to add another function, just drop the copied code from theme.inc into views_limit_grouping.module.

<?php
/**
 * Display the simple view of rows one after another
 */
function template_preprocess_views_limit_grouping(&$vars) {
  $view     = $vars['view'];
  $rows     = $vars['rows'];

  $vars['classes'] = array();
  // Set up striping values.
  foreach ($rows as $id => $row) {
    $row_classes = array();
    $row_classes[] = 'views-row';
    $row_classes[] = 'views-row-' . ($id + 1);
    $row_classes[] = 'views-row-' . ($id % 2 ? 'even' : 'odd');
    if ($id == 0) {
      $row_classes[] = 'views-row-first';
    }
    if ($id == count($rows) -1) {
      $row_classes[] = 'views-row-last';
    }
    // Flatten the classes to a string for each row for the template file.
    $vars['classes'][$id] = implode(' ', $row_classes);
  }
}
?>
mlbrgl’s picture

Another (temporary) option is to use views theme overrides and call the function mentioned in the above comments:

function YOURTHEME_preprocess_YOUR_VIEWS_DISPLAY(&$vars) {
  template_preprocess_views_view_unformatted($vars);
}
Jerome F’s picture

I'm trying to add first and last classes to the views fields groups, how could I adapt the code in #4 4 or the suggestion in #5 to do it ? (more details in the following issue : http://drupal.org/node/1086348)

Anonymous’s picture

Is it possible to have these classes by group like the normal group function does ?

Group 1:
class="views-row-1"
class="views-row-2"
class="views-row-3"

Group 2 :
class="views-row-1"
class="views-row-2"
class="views-row-3"

Thank you.

sokrplare’s picture

For anyone reading this thread and trying to apply it in D7, this module has unfortunately only been half-ported to D7 so a lot of things are funky.

Best example and most obvious reason none of these (otherwise sound) pieces of advice will work - take a look at views-limit-grouping.tpl.php which is not really based on the D7 version of views-view-unformatted.tpl.php (http://api.drupal.org/api/views/theme!views-view-unformatted.tpl.php/7).

I just needed odd and even so did a temporary hack to get that (since $zebra doesn't seem to exist anywhere, unless I'm missing something!):
OLD:
<div class="views-row views-row-<?php print $zebra; ?> <?php print $classes; ?>">
NEW:
<div class="views-row views-row-<?php print $id % 2 == 0 ? 'even' : 'odd'; ?> <?php print $classes; ?>">

sonu_dev’s picture

Issue summary: View changes
print $block_html_id; " class=" print $classes; " print $attributes; >

In the Above div tag having id and class,in which define some variables like $block_html_id; , $classes; , $attributes;. Can anyone help me out from where does these variables come from.