Skip to content

Instantly share code, notes, and snippets.

@lanche86
Last active December 17, 2015 16:49
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 lanche86/5642016 to your computer and use it in GitHub Desktop.
Save lanche86/5642016 to your computer and use it in GitHub Desktop.
WordPress, while print posts, every fourth has different classname
<?php while ( have_posts() ) : the_post(); ?>
<?php
if ($i % 4 == 3 ) $classname = 'large';
else $classname = 'small';
?>
<div class="program-<?php echo $classname; ?>">
<?php the_post_thumbnail( "program-size-$classname", array( "class" => "program-size" ) ); ?>
<h3><?php the_title(); ?></h3>
<p><?php the_content(); ?></p>
<?php $i++; ?>
</div>
<?php endwhile; ?>
@kasparsd
Copy link

It is better to use the post_class() function and the related filter -- see http://codex.wordpress.org/Function_Reference/post_class

@dimadin
Copy link

dimadin commented Aug 10, 2013

In the beginning I used $i++ (that you never defined, BTW!) and then I realized there is $current_post. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment