Query the posts like you are known to it, but then get all posts and restructure them for the order you need it. Take care of setting up the global $post
variable your own so that to ensure you template code still works.
The array_chunk
Docs function normally comes in handy for column based output:
$query = WP_Query($queryParameters);
if ($query->have_posts())
{
$columnCount = 3;
$rows = array_chunk($query->get_posts(), $columnCount);
foreach (range(0, $columnCount - 1) as $column)
{
printf("<div class=\"class-%dcolumn\">\n", $column + 1);
foreach ($rows as $row)
{
if (false == isset($row[$column]))
{
continue;
}
$post = $row[$column];
setup_postdata($post);
?>
... single post template html/php mixture ...
<?php
}
print("</div>\n");
}
}
Some additional notes:
- CSS class names can not start with a number. Please see the CSS specification and/or What characters are valid in CSS class names? – I prefixed those with
class-...
. - You might not need this exact source-order. If not, you can just output one post after the other and take care of column display with CSS only. That normally lightens up the template code a lot.