以表格形式显示最近发布的帖子

时间:2013-06-28 作者:Ruriko

在索引中。php模板我想以表格格式在3列中显示帖子。我该怎么做?我不想要列表格式,因为我有可变的高图像大小

2 个回复
最合适的回答,由SO网友:Krzysiek Dróżdż 整理而成

您仍然可以使用列表-只需使用适当的CSS(每三个li-每行的第一个li-应该clear 属性集;您可以使用CSS类或:n子选择器来执行此操作)。

如果您真的必须使用table(我不建议这样做-这不是一个好主意,因为它不是语义),您可以这样做:

<table>
<?php while ( have_post() ): the_post(); ?>
  <php if ( $wp_query->current_post % 3 == 0 ): ?>
     <?php if ( $wp_query->current_post ): ?>
     </tr>
     <?php endif; ?> 
     <tr>
  <?php endif; ?>
  <td>
     ... YOUR POST GOES HERE
  </td>
<?php endwhile; ?>
<?php $i = $wp_query->current_post; while ( $i % 3 != 0 ): $i++ ?><td></td><?php endwhile; ?>
  </tr>
</table>
并没有测试它,所以它可能有点问题,但想法应该很清楚。

SO网友:rfrq

基本上,这可以通过新的WP\\U查询完成:http://codex.wordpress.org/Class_Reference/WP_Query

    // args
    $args = array(
        \'post_type\' => \'post\'
    );
    // new WP_Query
    $items_query = new WP_Query($args);        
    // loop
    if ($items_query->have_posts()) {
        while ($items_query->have_posts()) {
            $items_query->the_post();
            $content_items .= \'<h2>\' . get_the_title() . \'</h2>\';
            $content_items .= get_the_content();
        }
    }
    // echo 
    echo $content_items;
    // reset
    wp_reset_postdata();
必须在循环中添加表的标记。您应该提供更多有关您希望帖子显示方向的信息,以创建完整的片段。例如:

     ----------------------------------
     - 1st post - 2nd post - 3rd post -
     ----------------------------------
     - 4th post - 5th post - 6th post -
     ----------------------------------
     -   ....   -   ....   -   ...    -
     ----------------------------------

     ----------------------------------
     - 1st post - 3rd post - 5th post -
     ----------------------------------
     - 2nd post - 4th post - 6th post -
     ----------------------------------
     -   ....   -   ....   -   ...    -
     ----------------------------------

结束

相关推荐

Open Graph in posts loop page

我有一个循环,所有帖子都有自己的like按钮,当我点击它时,facebook窗口会出现,但它不会显示正确的帖子缩略图。我认为这是正常的,因为在一个帖子循环中,缩略图是多个的,所以脚本无法判断哪一个去了哪里——相反,like按钮在我的单个帖子页面上工作得很好。所以我的问题是:有没有可能让类似facebook的按钮在循环页面上正常工作,这样即使页面中有10篇帖子,它也能抓取正确的帖子缩略图?也许我应该有多个开放图元,为循环中的每个帖子设置一个集合,但我想这只会造成混乱,我能做些什么吗?