如何创建垂直和按字母顺序排序的列


create columns, vertical and alphabetically sorted, how?

更新:更好的代码,谢谢!

这就是我想要的:

A   D
-   -
-   -
-   -
-   -   
B   E
-   -
-   -
-   -
-   -
C   F
-   -
-   -
-   -
-   -

一直在尝试创建9列,输出垂直和按字母顺序排序的帖子列表。有一点帮助,我有一个循环,我认为输出正确,但不确定,我不确定如何样式它。我要么得到一个直列,要么得到水平排序。这是循环和测试端:http://skateflix.se/test2/

 <?php
   $last_char = '';
   $args=array(
   'post_type' => 'portfolio',
   'orderby' => 'title',
   'order' => 'ASC',
   'posts_per_page'=>-1,
   'portfolio-category' => 'indie',
   'ignore_sticky_posts'=>1
 );
 $my_query = new WP_Query($args);
 $columnCount = 0;
 ?>
<?php if( $my_query->have_posts() ) : ?>
 <?php  echo 'Alphabetic index of all ' . count($my_query->posts) . ' posts'; ?>
<table>
    <tr>
        <?php while ($my_query->have_posts()) : ?>
            <?php if ($columnCount == 8): ?>
                </tr>
                <tr>
                <?php $columnCount = 0; ?>
            <?php endif; ?>
            <td>
            <?php $my_query->the_post(); ?>
            <?php $this_char = strtoupper(substr($post->post_title,0,1));  
             if ($this_char != $last_char) : ?>
          </table></td><td>
       <?php   $last_char = $this_char; ?>
       <h2> <?= $last_char; ?></h2>
      <table>
     <?php else: ?>
      <tr><td><p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent     Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p></td></tr>
 <?php endif; ?>

        <?php endwhile; ?>  
        <?php if ($columnCount != 8): ?>
            </tr><!-- Make sure the last row gets closed. -->
        <?php endif; ?>
   </table>
  <?php endif; ?>

在黑暗中拍摄,但试试这个:

 <?php if ($this_char != $last_char) :
     </table></td><td>
     $last_char = $this_char; ?>
     <h2> <?= $last_char; ?></h2>
     <table>
 <?php else: ?>
         <tr><td><p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p></td></tr>
 <?php endif; ?>

确保在<?php endwhile; ?>之前去掉</td>