Update: Got something working, and an output with a post list. However, i can't get it to break on columns. tried css on it for an hour now.. any suggestions? Testsite: http://skateflix.se/test2/
I have a vertical list of post sorted alphabetically. How do i break this up in 9 columns? Tried every plugin on the market, every code snippet i can find, nothing. Must be a way? Exampel: http://skateflix.se/test-2/
This is my 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(). ?>
this is the output i want (but in 9 columns):
A D
- -
- -
- -
- -
B E
- -
- -
- -
- -
C F
- -
- -
- -
- -
<?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>
This will hopefully work for your specific example.
<?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(). ?>