Div class 名字和 $count;在 wordpress 循环中

Div class name with $count; in wordpress loop

我需要添加一个$count;在类名到循环内的 post div 之后。含义示例:- 所以 类 for posts 将是 mypost1, mypost2...

我做的很好,但我不知道如何在类名后添加 $count。

<?php $count = 0; if ( have_posts() ) : while ( have_posts() ) : the_post(); $count++; ?>
<div class="mypost">...</div>
<?php endwhile; endif; ?>

只需echo你的变量在适当的地方:

<?php $count = 0; if ( have_posts() ) : while ( have_posts() ) : the_post(); $count++; ?>
<div class="mypost<?php echo $count; ?>">...</div>
<?php endwhile; endif; ?>