可以使用php模数%
操作人员
让我们使用您的代码。
<?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; ?>
添加
$count=1
然后在您的内容中。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="<?php the_permalink(); ?>"><?php echo get_the_post_thumbnail($id, array(220,220)); ?></a>
</div>
<div class="bot">
<a href="<?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; ?>
使
$count
变量全局,以便可以访问。
这是主要部分
剩余的$count
除以3
并添加:
<div class="goods_list catalog_goods <?php echo $no_margin; ?>">
回响
$no_margin
最后添加:
<?php ++$count; ?>
因此,它将不断增加,直到循环完成。