Is there a way to print an even & an odd row within the <li> tag?

The idea is to have this structure:

  <li class="views-row views-row-1 views-row-odd views-row-first">        
    <div class="views-field-title">                       
      <span class="field-content">      
        <a href="/testview/node/11" title="post-10" alt="post-10"> post-10</a>    
      </span>       
    </div> 
    <div class="views-field-title">                       
      <span class="field-content">      
        <a href="/testview/node/10" title="post-9" alt="post-9"> post-9</a>    
      </span>       
    </div>        
  </li>

here's a template I'm using:

<?php
// $Id: views-view-list.tpl.php,v 1.3 2008/09/30 19:47:11 merlinofchaos Exp $
/**
 * @file views-view-list.tpl.php
 * Default simple view template to display a list of rows.
 *
 * - $title : The title of this group of rows.  May be empty.
 * - $options['type'] will either be ul or ol.
 * @ingroup views_templates
 */
?>
<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>

Any help is greatly appreciated...

Thanks!

Comments

dawehner’s picture

<?php
// $Id: views-view-list.tpl.php,v 1.3 2008/09/30 19:47:11 merlinofchaos Exp $
/**
* @file views-view-list.tpl.php
* Default simple view template to display a list of rows.
*
* - $title : The title of this group of rows.  May be empty.
* - $options['type'] will either be ul or ol.
* @ingroup views_templates
*/
?>
<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 ($id % 2) ? print 'views-row-odd' : print 'views-row-even'; ?>">
      <?php print $row; ?>       
      </li>
    <?php endforeach; ?>
  </<?php print $options['type']; ?>>
</div>
esmerel’s picture

Status: Active » Closed (fixed)

Solution given, no response.

Naiya’s picture

i confirm - this solution is fine.

You may want to add " == 0 " to the condition.