I'm trying to modify search-result.tpl.php and template.php to color the backgrounds of search results returned such that every row has a different color than the one that preceded it. Only two colors are used. so, row #1 returned would have background #eee and row 2 would have #ff0000 as its background color. It would start over again at row #3 having #eee and so on. This is easily enough accomplished with PHP. But how can I implement this with Drupal?
Here's how I'm trying to print it out in search-result.tpl.php:
<li class="<?php print $classes; ?>"<?php print $attributes; ?>>
<div class="search-snippet-info">
<?php $inc=0; ?>
<?php if ($inc %2 == 0) {
$color = '#eee';
} else {
$color = '#ff0000';
}
?>
<div style="background-color: <?php print $color ?>">
<div class="icon" style="float:left;"><?php print render($teaser['field_icon']); ?></div>
<div class="teaser">
<header>
<h2><a href="<?php print $result['link']; ?>"><?php print $result['title']; ?></a></h2>
</header>
<em><?php print render($teaser['field_type']); ?></em>
<strong><?php print render($teaser['field_event_dates']); ?></strong>
<?php print render($teaser['body']); ?>
</div>
<?php $inc++; ?>
</div>
</div>
</li>
Not getting errors, but the results are not what I was expecting. Each row is just returning the same color background #eee, the first color). So either the $inc variable is not getting incremented or (perhaps more likely) it's becoming '0' again after every returned result. So then I'm thinking maybe I need to add something to my preprocess_search_result function in my template.php file...but I don't know what to add there.
Any help would be greatly appreciated.