You can do with php modulus %
operator.
Lets work with your code.
<?php if ( have_posts() ) : ?>
<?php twentyeleven_content_nav( 'nav-above' ); ?>
<?php /* Start the Loop */ ?>
<?php $count = 1; ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
/* Include the Post-Format-specific template for the content.
* If you want to overload this in a child theme then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
?>
<?php endwhile; ?>
Add $count=1
Then in your content.php:
<?php
global $count;
if ($count % 3 === 0) {
$no_margin = 'last';
}
?>
<div class="goods_list catalog_goods <?php echo $no_margin; ?>">
<div class="goods_item">
<div class="foto">
<div class="shadow"></div><?php the_excerpt(); ?>
<a href="https://wordpress.stackexchange.com/questions/112768/<?php the_permalink(); ?>"><?php echo get_the_post_thumbnail($id, array(220,220)); ?></a>
</div>
<div class="bot">
<a href="https://wordpress.stackexchange.com/questions/112768/<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
<div class="stars"></div>
<div class="order">
<a class="but_buy"><i class="icon-shopping-cart icon-large"></i> Buy </a>
<span class="price">$45.00</span>
</div>
</div>
</div>
</div>
<?php ++$count; ?>
Make the $count
variable global so it can be accessible.
Heres the main part
Remainder of $count
divided by 3
and add:
<div class="goods_list catalog_goods <?php echo $no_margin; ?>">
echo $no_margin
At the last add:
<?php ++$count; ?>
so it will increment until the loop finishes.