只需使用简单的 CSS 即可。应该工作到IE7。
.article {
width: 170px;
}
.article:first-child {
border-bottom: 1px dotted #000000;
}
注意:如果您的第一个孩子是像评论这样的文本节点,IE7 中的 :first-child 实现有点错误。
:first-child 将匹配项目 1
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
:first-child 与第 1 项不匹配,因为该评论。
<ul>
<!-- Comment -->
<li>Item 1</li>
<li>Item 2</li>
</ul>
解决方法
<ul><!-- Comment --><li>Item 1</li>
<li>Item 2</li>
</ul>
或者只是删除评论。
您还可以在 while 循环中计算您的迭代次数。那不是一个优雅的方法,但应该适合你......
<?php
//Set Counter to 0
$counter = 0;
// Start Loop
if ( have_posts() ) while ( have_posts() ) : the_post();
// Increment Coounter
$counter++;
?>
<div class="span content item-<?php echo $counter; ?>">
<h2><?php the_title(); ?></h2>
<p><?php the_content(); ?></p>
</div><!-- /.span8 .content -->
<?php endwhile; ?>
WP-Loop 的每次迭代都会将 $counter 增加 1。
第一次迭代:
<div class="span content item-1">
第二次迭代:
<div class="span content item-2">
第三次迭代:
<div class="span content item-3">
... 等等。