How can I output a loop of records with two different templates? I need all evens to be with one pattern - odd with another. I would be grateful for the help.

  • Count the records, take the remainder of the integer division of the counter into two, compare it with zero, and branch. In general, it’s customary to show your code here. - KAGG Design
  • It would be nice to show the template codes, perhaps there are other ways - malginovdesign

1 answer 1

Something like that :

$num = 1; foreach($posts as $single_post) { if(($num % 2) == 0) { //если четное, выводим 1 шаблон } else { //если нечетное, выводим 2 шаблон } $num++; }