Wordpress:第一篇文章的风格与其他文章不同


Wordpress: Style first post differently from the rest

我一直在四处寻找,但找不到合适的解决方案。我的目标是第一个帖子的风格与其他帖子不同。我把它们放在一个3*3的网格中,我希望第一个帖子是全宽的。

以下代码在index.php.中生成循环

<ul class="list_post">
            <?php $i = 1; ?>
            <?php if (have_posts()) : while (have_posts()) : the_post(); ?>                    
                <?php get_template_part('content','grid'); ?>                                          
                <?php if ($i%3 == 0) : ?>
                    <div class="clearfix"></div>
                <?php endif; $i++; ?>
            <?php endwhile; wp_reset_query(); endif; ?> 
</ul>

呈现的HTML输出为:

<ul class="list_post">
  <li>
    <article id="post-7375" class="post_grid post-7375 post type-post status-publish format-video has-post-thumbnail hentry post_format-post-format-video">
      <div class="post-img"></div>
      <div class="post-header"></div>
      <div class="post-entry"></div>
    </article>
  </li>
  <li>(..)</li>
  <li>(..)</li>
</ul>

我不知道该怎么做?

content-grid.php上,更改前几行以反映以下内容:

global $i;
<article id="post-<?php the_ID(); ?>" <?php post_class('article-num-' . $i); ?>>

然后在你的CSS中,你可以做:

.article-num-1{
..
}