The theme system in WordPress is one of its great strengths and something that is loved by most WP users. It’s a very good thing. However, different developers like setting up code in different ways.
While the theme system works well as advertised, it doesn’t work exactly the way I like to set up my web front-end code. Luckily, it is so flexible that I can easily implement my preferred system.
The standard theme set-up has a header file, footer file, sidebar file and index, single and page files that include the header, footer and sidebar. This is all well and good, but if you make a change to your overall layout, you often have to make it in 3 places (the index, single and page files).
I prefer a template approach, where I have a master template that has a few
I’ve set up my master template, with the holes and display logic I need to keep the site consistent and only have to make changes in one place. This contains the code that would normally be in the header file, the footer file an some of the index, page, single and sidebar files.
In the index, page, single and sidebar files, I buffer the output into variables instead of spitting the content out directly. Then at the end of each template file, I include my master template, which places each variable nicely into it’s home in the template and outputs the page.
This allows the template system to follow the theme convention of having different pages, while allowing me to control the master site code in a single place.
If you’re tired of editing several files when you want to make a change that (for example) affects both your “page” templage and your “single” template, you may want to consider this approach.
Popularity: 4% [?]


Ideologist adds this Comment:
Excelent idea! Can you post or offer an example file for us to see how it is done? Thank you.
September 22nd, 2006 at 5:42 pm
Matt adds this Comment:
I may have misread, but why not just have an index.php and not use get_header or get_footer? You could then use condititionals (or the standard functions like get_sidebar) to bring in different parts of the page.
September 22nd, 2006 at 6:00 pm
Alex adds this Comment:
I’m not 100% sure I follow your comment either, but the ability to choose a different template on a per-page basis is still something I need.
September 22nd, 2006 at 6:06 pm
Randy adds this Comment:
Many theme authors use a “loop.php” filled with if statements to do something similar to what you do, Alex. I prefer the flexability of multiple files: single.php, index.php, home.php, page.php, etc.
September 22nd, 2006 at 6:50 pm
Alex adds this Comment:
Exactly, this gives me that benefit.
September 22nd, 2006 at 6:54 pm
Abhijit Nadgouda adds this Comment:
Is this like Smarty? The individual files deal with only retrieval of data. The data is actually displayed in the master template.
September 22nd, 2006 at 8:09 pm
Compuntoes adds this Comment:
good idea (:
September 22nd, 2006 at 8:11 pm
Tipunch adds this Comment:
I also would appreciate seeing an example, a set of your main files as described with their holes, to fully appreciate your approach.
September 22nd, 2006 at 11:38 pm
Innovation Wings » WordPress: Themes vs. Templates adds this Pingback:
[...] Nachdem bei Joomla vor einiger Zeit die Diskussion losgegangen ist, wie Content und Präsentation am besten voneinander getrennt werden können, und wie ein universelles, einfach handzuhabendes System aufgebaut werden muss, startet diese Diskussion jetzt auch bei WordPress. [...]
September 23rd, 2006 at 1:53 am
Perun adds this Comment:
Hi Alex,
1. lot of people prefer that index, page and single file looks different. So its not everytime necessary to put the same change in index, single and page.
2. if you like to have it in one file you can make only index and with if-statements etc. you can realize the output for single site, page or main site …
3. please not smarty! i saw smarty in action in xtcommerce, joomla and in serendipity. And smarty is for me pain in the neck. Comparing to this: the themesystem of WP is great and easy to understand … above all for people they are not programmers.
Sorry for my bad english and i hope you can understand me.
4.
September 23rd, 2006 at 3:02 am
milo adds this Comment:
Totally agree with you, as “Ideologist” said, can you show us an example please.
September 23rd, 2006 at 4:17 am
Craig Hartel adds this Comment:
While the system currently in use is a boon to those who know WP very well, it’s a huge mess to those of us who are less code-savvy. Just about every template is so unique that it makes it hard to transfer your own design ideas or changes from one to the other.
Me? I’m not a fan of the system. It’s too complex for most users to truly understand.
September 23rd, 2006 at 8:20 am
Noel Cower adds this Comment:
It’s an interesting approach to controlling content placement. I’ll keep this in mind while I’m redesigning my site — who knows, could make my life a whole lot easier.
Thanks for the insight.
September 24th, 2006 at 1:16 am
Aaron Murphy adds this Comment:
I have been working out this same approach on my site recently. I want to minimize the number of templates I use, maximize the number of includes but still stay as flexible as possible.
As Randy mentioned above, I’ve seperated out the loop into an include file. Which gives me the ability to use different loops not just entire templates.
What I’m dealing with right now is setting up my templates so I can call specific categories and specific pages, as well as specific formatting by using logic. My goal is to have 1-2 main templates (index.php/page.php) take care of most of the site.
This is my index.php page right now,
Much cleaner than what I used to have before I removed the loop.
September 24th, 2006 at 2:50 pm
Aaron Murphy adds this Comment:
Oops, I guess you can’t use carat – code, here is a link. http://www.aaronspor[...]242006_a.txt
September 24th, 2006 at 2:52 pm
Tingting adds this Comment:
well said.!
September 25th, 2006 at 5:56 am
Alex King: WordPress Themes Versus Templates « Lorelle on WordPress adds this Pingback:
[...] Alex King’s “WP Themes vs. Templates” discusses the modular system of how WordPress Themes work with some good tips on creating a template form to work within your WordPress Theme. While the theme system works well as advertised, it doesn’t work exactly the way I like to set up my web front-end code. Luckily, it is so flexible that I can easily implement my preferred system. [...]
October 20th, 2006 at 12:24 am
Srijit adds this Comment:
Joomla does not use smarty. it uses pattemplate.
It is somewhat like Alex envisions. One singe file defines the look for the entire site. Much easier to edit than multiple pages in a wordpress setup. But to be fair, i havent found wordpress templates to be that bad either. smarty on the other hand makes me want to cry
January 24th, 2007 at 10:20 am
wordpress from malaysia adds this Comment:
i agree with you alex.
i’m not a good programmer, so…i’m not really understand with your tips on how you do it.
however, its open my eyes..because editing 3 files for any wp themes is too much confusing to me!!..hahaha
September 7th, 2007 at 9:23 am