Applying Even/Odd Classes – Alternate class to each LI foreach

I am trying to give an alternate class to each LI foreach.

i.e.

<li class="odd">
text
</li>
<li class="even">
text
</li>
<li class="odd">
text
</li>
<li class="even">
text
</li>
This is my code:
$toggle = ($toggle=="alignleft"?"alignright":"alignleft");

<ul>
<?php foreach ($this->item->extra_fields as $key=>$extraField): ?>
<?php if($extraField->value): ?>
<li class="<?php echo $toggle; ?>>
Text here
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s