phprowcol

PHP Loop based on row number for bootstrap columns


I have one design issue that I want to solve. I've spend 2 days on this and I know that its an easy one...

I want to echo the articles with this order: col-8, col-4, col-4, col-8, col-8,col-4... and so on.

enter image description here

I've made it to echo the articles like this: col-8, col-4, col-8, col-4, col-8, col-4... and so on.

if ($article->id % 2 == 0) { echo 4; } elseif ($article->id % 2 == 1) { echo 8; }

I know that I have to use the loop inside one other loop, but I am stuck.


Solution

  • You need to adjust your modulus conditional to fit the loop / starting point you want.

    Give this a go:

    if ($article->id % 4 == 0 || $article->id % 4 == 1) { echo 8; } else { echo 4; }
    

    https://ideone.com/IneWWC