我正在建立一个网站(使用Wordpress 3.6),并希望将新闻/文章排列如下:
-第一篇文章是最大尺寸(一列);
-以下文章分为两列。
每页仅显示 5 或 7 篇文章。有人可以帮我做这件事吗?请!
问候
下面是执行以下操作的循环:
查询最新 7 帖子
在第一列中显示第一个帖子
其余 6 个在具有相同类的两个div 中,您可以设置样式以形成列
<?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;
?>
在这里回答:https://wordpress.stackexchange.com/questions/115128/first-article-single-column-other-articles-2-columns
谢谢大家!:)