我正在建立一个网站(使用 Wordpress 3.6),并希望将新闻/文章安排如下:
- 第一篇文章是最大尺寸(一栏);
- 以下文章分两栏排列。
每页仅显示 5 或 7 篇文章。有人可以帮我做到这一点吗?请!
问候,
这是执行以下操作的循环:
查询最新的 7 个帖子
在第一列显示第一篇文章
两个具有相同类的 div 中的其余 6 个,您可以设置样式以形成列
<?php
$count = 1; // this is the variable that will count how many posts have been shown
$my_query = new WP_Query('posts_per_page=7');
if ($my_query->have_posts()) : while($my_query->have_post()) : $my_query->the_post();
if($count == 1) { // this is the output for the first post
?>
<div id="full-post">
// post contents
</div><!-- end .full-post -->
<?php $count++; // here we increment the counter
} elseif ($count == 2 || $count == 5) { ?>
<div class="column"> // notice that only on 2nd and 5th iteration we are only opening the column div
<div class="post-container">
// post contents
</div><!-- end .post-container -->
<?php count++; ?>
} elseif ($count == 4 || $count == 7) { ?>
<div class="post-container">
//post contents
</div><!-- end post.container -->
</div><!-- end .column --> // here we are closing the column div
<?php $count++;
} else { ?>//these are just normal posts
<div class="post-container">
//post contents
</div><!-- end post.container -->
<?php $count++;
}
endwhile;
endif;
?>
谢谢大家!:)