如何在一列中显示第一篇文章,在两列中显示其他文章?wordpress



我目前将所有帖子显示在一列中:

1
2
3

我想实现类似的目标:

1
23
4
56

有人知道我该怎么做吗?有可能吗?提前非常感谢:)

现在我有:

<?php if( $wp_query->current_post <= 0 ) : ?>
code for the first one column post
<?php else : ?>
the rest of the posts styled in columns
<?php endif; ?>

我为这个问题找到的解决方案是使用默认循环的$wp_query->current_post,在添加到主题中的functions.php文件的过滤函数中,当post的div是post_class()

function special_recurrent_post_class($classes) {
      if( is_home() ) {
      global $wp_query;
      $extra_classes = array('','specific','specific','');
      $classes[] = $extra_classes[$wp_query->current_post%count($extra_classes)];
      }
      return $classes;
}
add_filter('post_class', 'special_recurrent_post_class');

上面的示例将此限制为主页或帖子页面上的帖子;否则,您需要将编码标记is_home()更改为其他内容。

只需使用这样的计数器:

// before loop
$ctr = 1; 
if ($ctr == 1) {
    *** code for one column; ***
    $ctr ++;
} else {
    *** code for two column; ***
    $ctr++
    if ($ctr == 4) $ctr = 1   // Reset the counter, back to one column
}

最新更新