如何在第一栏中显示第一篇文章,在第二栏中显示其他文章? WordPress的 [英] how can I display the first post in a single column and others in 2 columns? wordpress
问题描述
我目前在一栏中显示所有帖子:
I currently have all the posts displayed in one column:
1
2
3
...
1
2
3
...
我想实现类似的目标:
1
23
4
56
...
1
23
4
56
...
有人对我该怎么做有任何想法吗?是否有可能? 提前非常感谢您:)
does anyone have any ideas of how I could do this? is it possible? thank you so much in advance :)
现在我有:
<?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; ?>
推荐答案
我为此问题找到的解决方案是在主题中添加到functions.php
文件的过滤器函数中使用默认循环的$ wp_query-> current_post. ,当发布的div为post_class()
The solution I found for this problem was using the $wp_query->current_post of a default loop, in a filter function added to functions.php
file in the theme, when post's div is 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()
更改为其他标记.
The example above restricts this to posts on the home page or posts page; otherwise, you need to change the coditional tag is_home()
to something else.
这篇关于如何在第一栏中显示第一篇文章,在第二栏中显示其他文章? WordPress的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!