Skip to content

Instantly share code, notes, and snippets.

@gregrickaby
Last active November 26, 2018 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save gregrickaby/6189818 to your computer and use it in GitHub Desktop.
Save gregrickaby/6189818 to your computer and use it in GitHub Desktop.
Add post count class to WordPress loop
<?php
// Count the posts and give them each a unqiue number as a css class
$count = 1;
while ( $query->have_posts() ) : $query->the_post(); $count <= 100; ?>
<div class="count-<?php echo $count++; ?>">
<p class="headline"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
</div>
<?php endwhile; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment