I\'m trying to create the following front-end using a PHP loop and Twitter Bootstrap\'s 12 column grid system:
The HTML output is:
Everytime I need to to this, I just use array_chunk
to build a proper array chunk for my rows and columns.
For example You have:
$posts = [['id' => 1], ['id' => 2] ...]
Instead of looping and calculating whether to add row, make chunks of your posts:
$posts = [['id' => 1], ['id' => 2] ...]
$postChunks = array_chunk($posts, 4); // 4 is used to have 4 items in a row
foreach ($postChunks as $posts) {
foreach ($posts as $post) {
=$post['id'];?>
}
}