0

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.

diggy
  • 6,748
  • 2
  • 18
  • 24
george
  • 167
  • 1
  • 4
  • 16
  • Take a look at how the templates are loaded in the source: https://core.trac.wordpress.org/browser/tags/4.0/src/wp-includes/template-loader.php#L44 – diggy Nov 12 '14 at 18:37
  • Thanks to all of you! The answers make total sense. Just to give you more background info: in my experience, the difference between archive, single, etc. usually is just a few lines of code within the loop. But for bigger design changes I have to alter several files, if I use Version B. So I thought about trying Version A (one structural file which includes different loops). – – george Nov 12 '14 at 18:50

3 Answers3

2

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

rnevius
  • 26,578
  • 10
  • 58
  • 86
  • Marked as accepted answer because of background info and sound reasoning! Killer argument #1: index.php is LAST template. Killer argument #2: each template does a single thing, and does that thing well. (What a nice quote for a poster ;-)) – george Nov 12 '14 at 18:46
1

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.

Community
  • 1
  • 1
Yavor
  • 671
  • 3
  • 9
0

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.