<?php $posts = range(1, 10); // Collect all of your posts into an array, as an example I'm just using numbers. $posts_reordered = ['left' => [], 'middle' => [], 'right' => []]; foreach(array_chunk($posts, 3) as $chunk) { $posts_reordered['left'][] = $chunk[0]; if(isset($chunk[1])) { $posts_reordered['middle'][] = $chunk[1]; } if(isset($chunk[2])) { $posts_reordered['right'][] = $chunk[2]; } } // Now, print HTML $i = 1; foreach($posts_reordered as $key => $column_posts) { $outer_div_class = ".$key"; // .left echo "<div class='$outer_div_class'>\n"; foreach($column_posts as $post) { $inner_div_class = ".col$i"; echo "\t<div class='$inner_div_class'>$post</div>\n\n"; } echo "</div>\n"; $i++; }
You have javascript disabled. You will not be able to edit any code.