Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

kasparsd commented Aug 10, 2013

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

@dimadin

This comment has been minimized.

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