我目前将所有帖子显示在一列中:
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; ?>
我目前将所有帖子显示在一列中:
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主题文件的过滤器函数中,当帖子的 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
}