Hi,

I'm wondering if there's a way to display even and odd row within the <li> tags.

This is what I have:

<li class="views-row views-row-1 views-row-odd">  
  <div class="views-field-title">
                <span class="field-content">blah blah</span>
  </div>        
</li>
<li class="views-row views-row-2 views-row-even">  
  <div class="views-field-title">
                <span class="field-content">blah blah</span>
  </div>        
</li>

And this is what I would like to have:

<li class="views-row views-row-1 views-row-odd">  
  <div class="views-field-title">
                <span class="field-content">blah blah</span>
  </div>        
  <div class="views-field-title">
                <span class="field-content">blah blah</span>
  </div>        
</li>

in other words, I would like to have 2 records within the <li> tag. The reason why I need this because I'm trying to get a 2-row carousel working.

I tried jQuery (append, prepend, remove, empty, before, after) but with no success.

Now, I'm looking into modifying my views template:

<div class="item-list">
  <?php if (!empty($title)) : ?>
    <h3><?php print $title; ?></h3>
  <?php endif; ?>
  <<?php print $options['type']; ?>>
    <?php foreach ($rows as $id => $row): ?>
      <li class="<?php print $classes[$id]; ?>">
      	<?php print $row; ?>        
      </li>
    <?php endforeach; ?>
  </<?php print $options['type']; ?>>
</div>

Perhaps there is an answer in modifying <?php print $row; ?>

Any suggestions are greatly appreciated.

Thanks!

Comments

aaronchristian’s picture

Hi vasheck;

One way you can achieve odd/even or "zebra" striped list items is by setting the $zebra variable to odd and even, then telling the variable that it doesn't equal odd or even anymore so that the next statement prints the opposing class. Hope that makes sense. Dries has noted that this will be a standard option in D8 (http://drupal.org/node/192909).

See below;

<?php foreach ($rows as $id => $row): ?>
   <li class="<?php print $zebra ? 'odd' : 'even'; $zebra = !$zebra; ?>"><?php print $row; ?></li>
<?php endforeach; ?>

or if you'd like to keep the "views-rows" classes etc. you can add that variable to the end of the $zebra statement.

<?php foreach ($rows as $id => $row): ?>
   <li class="<?php print $zebra ? 'odd' : 'even'; $zebra = !$zebra; $classes[$id]; ?>"><?php print $row; ?></li>
<?php endforeach; ?>