Skip to content

Instantly share code, notes, and snippets.

@dospuntocero
Created September 9, 2018 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dospuntocero/8138978be0674402b984efef584c2704 to your computer and use it in GitHub Desktop.
Save dospuntocero/8138978be0674402b984efef584c2704 to your computer and use it in GitHub Desktop.
use this if you need a foreach with even/odd classes
<?php
$recent_posts = wp_get_recent_posts();
?>
<?php $current_class = 'odd';?>
<?php foreach( $recent_posts as $recent ):?>
<?php $current_class = ($current_class == 'odd') ? 'even' : 'odd'; ?>
<div class="<?php echo $current_class ?>">
<?php echo $recent["post_title"]?>
<a href="<?php echo get_permalink($recent["ID"])?>">READ MORE</a>
</div>
<?php endforeach;?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment