Skip to content

Instantly share code, notes, and snippets.

@priyabratary
Created April 13, 2016 07:19
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 priyabratary/beb0e9b005584eb3f7d5449e9c56b646 to your computer and use it in GitHub Desktop.
Save priyabratary/beb0e9b005584eb3f7d5449e9c56b646 to your computer and use it in GitHub Desktop.
unique id each post
<?php $post_counter = 0; // start a counter before the loop ?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php $post_counter++; // increment the counter for each post ?>
<article <?php post_class(); ?> id="layout-<?php echo $post_counter; ?>">
<?php if ( $post_counter <= 3 ) : ?>
// display something only for the third post in the loop
<?php endif; ?>
// the loop content goes here
</article>
<?php endwhile; ?>
<?php else : ?>
// not found page
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment