A simple solution would be to add an alternating class to every other post in the list. In particular, (in your style.css) style the list elements <li>
in one particular way, and then over-ride that style for list elements of a particular class <li class="my-alternate-class">
. The class my-alternate-cass
will applied to every other list element:
<?php global $post;
$args = array('post_type' => 'events');
$custom_posts = get_posts($args);
if($custom_posts):?>
<ul>;
<?php foreach($custom_posts as $post) : setup_postdata($post);?>
<?php $class = (empty($class) ? "class="my-alternate-class"" : "");?>
<li <?php echo $class;?>>Content goes here</li>
</ul>;
<?php endforeach; ?>
<?php endif; ?>
//Remember to wp_reset_postdata() afterwards
wp_reset_postdata();
?>
Please note this untested.
I’ve also added wp_reset_postdata()
as otherwise your site might break.