Note: This is a self Q&A
When building asymmetrical grid layouts in WordPress, it’s common that you’d want to wrap each X post in a div, like so:
div
post
post
/div
div
post
post
/div
div
post
post
/div
I’d like to avoid using a modulo operator as it gets confusing quickly.
Most people do this with a modulo operator, but it gets awkward to do it if no posts are found, or and even division occurs on the last post. I’ve expanded on the answer provided here by @The Shift Exchange to do it in a cleaner way.
You would change the “2” in the first foreach loop to be the amount you want grouped per row.