Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
WordPress, while print posts, every fourth has different classname
<?php while ( have_posts() ) : the_post(); ?>
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++; ?>
<?php endwhile; ?>
Copy link

kasparsd commented Aug 10, 2013

It is better to use the post_class() function and the related filter -- see


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