george
george

Reputation: 187

About Wordpress theme architecture: one index.php vs. multiple template files

Just a quick questions to all you WordPress wizards out there regarding WordPress theme architecture: what’s better in terms of performance, syntax, maintenance, etc.?

Version A:

One index.php that includes external parts (different loops and other structural) elements depending on if is_page, is_archive, is_single, is_tax, etc.

or

Version B:

Separate files for index.php, pages.php, single.php, archive.php, etc.

Upvotes: 0

Views: 4280

Answers (3)

Yavor
Yavor

Reputation: 671

If our website has very similar pages then one index.php might work for you. For all other cases having code in separate files will be crucial to being able to easily manage and grow your site. The more messy the code is the more potential problems you'll get.

In terms of performance I think it won't make much of a difference. You can track it using a timer - Accurate way to measure execution times of php scripts

I usually put the initial time tracker in the index.php in your root folder and then the final time tracker in the footer. This way you can easily see the difference in total execution time.

Upvotes: 1

Pablo Siciliano
Pablo Siciliano

Reputation: 21

For me at least, version B. It's too easy for a designer a simple structure for template, and it's typical and traditional on wordpress.

Upvotes: 0

rnevius
rnevius

Reputation: 27102

Version B is going to be better from a performance, as well as an organizational standpoint.

Take a look at the way template files are called to generate a WordPress page based on the WordPress Template hierarchy. This is straight from the Codex on Template Hierarchy.

enter image description here

As you can see, index.php is the LAST template that is looked for during a request.

Also, and perhaps more subjective, is that breaking the templates into individual files makes things easier to maintain, as you don't have one HUGE file with conditional statements. Each template does a single thing, and does that thing well.

EDIT: Well, I was hoping you'd be able to see the image...but here's the original from the Codex: http://codex.wordpress.org/images/9/96/wp-template-hierarchy.jpg

Upvotes: 2

Related Questions