wordpress,按字母顺序分列多栏中的帖子垂直列表?

时间:2014-08-22 12:10:15

标签: php wordpress

更新:有一些工作,以及带有帖子列表的输出。但是,我不能让它在列上打破。现在尝试了css一小时..任何建议? Testsite:http://skateflix.se/test2/

我有一个按字母顺序排序的垂直列表。我如何在9列中打破这个?试过市场上的每个插件,我找不到任何代码片段。一定是一种方式?例子:http://skateflix.se/test-2/

这是我的wp_query:

<?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 wp_reset_query();  // Restore global post data stomped by the_post(). ?>

这是我想要的输出(但在9列中):

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

1 个答案:

答案 0 :(得分:0)

<?php $columnCount = 0;?>

<table>
    <tr>
        <?php foreach($postArray as $post): ?>
            <?php if ($columnCount == 8): ?>
                </tr>
                <tr>
                <?php $columnCount = 0; ?>
            <?php endif; ?>
            <td><!-- Put your output here --></td>
            <?php $columnCount++; ?>
        <?php endforeach; ?>
        <?php if ($columnCount != 8): ?>
            </tr><!-- Make sure the last row gets closed. -->
        <?php endif; ?>
</table>

这有望适用于您的具体示例。

<?php

$last_char = '';
$args=array(
    'post_type' => 'portfolio',
    'orderby' => 'title',
    'order' => 'ASC',
    'posts_per_page'=>-1,
    'portfolio-category' => 'fullvids',
    'caller_get_posts'=>1
);

$my_query = new WP_Query($args);

$columnCount = 0;

?>

<?php if( $my_query->have_posts() ) : ?>
    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)); ?>

                <?php if ($this_char != $last_char) :
                    <?php $last_char = $this_char; ?>
                    <h2> <?= $last_char; ?></h2>
                <?php endif; ?>

                <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
                </td>                
            <?php endwhile; ?>  //if ($my_query)

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

<?php wp_reset_query();  // Restore global post data stomped by the_post(). ?>