Why do themes rely on “The Loop”?

I’ve been looking at WordPress themes development recently, and I’m trying to understand why WordPress is coded with “The Loop”, rather than providing an array of posts that you can loop through with a foreach.

It just seems to add complexity for theme development, but surely if they went out of there way to create this concept of “loop” there must be a reason?

4 s
4

You are thinking of WordPress templates as PHP application code. Essentially they are not that.

WordPress templates by design are templates using Template Tags API. It is extra level of abstraction, that just happens to allow to use rest of PHP language too.

The ease of template tags serves the popularity of WordPress and extremely low entry bar for people to tweak themes. Believe me, there are plenty of people around who use/tweak loops without much understanding of what they actually are, in extreme cases, what arrays even are.

Leave a Comment