Wordpress:第一篇文章,一篇专栏文章;其他文章,2列

时间:2013-09-21 13:12:20

标签: php wordpress

我正在建立一个网站(使用Wordpress 3.6),并希望将新闻/文章排列如下:

- 第一篇文章是最大尺寸(一列);

- 以下文章分为两栏。

每页只显示5或7篇文章。有人可以帮我这么做吗?请!

此致

2 个答案:

答案 0 :(得分:0)

以下是执行以下操作的循环:

查询最新的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;
?>

答案 1 :(得分:0)