I was helping out a friend a few days with their fairly complicated WordPress website. Complicated because it had over 40 different page templates, rendered exclusively by PHP.
Anyway, when this friend of mine was porting the site over from his development environment to production, he had to recreate those 40 pages, make sure their slugs matched, and assign the appropriate page template from that drop-down list of over 40 times. What a nightmare!
I thought there should be an easier way. One that would work similar to page templates, but without that extra database overhead, without the UI and everything else. Obviously this would render a WordPress theme completely useless outside of the original context, but so do 40 page templates.
I drafted up a plugin, a proof of concept, and called it Static Templates. The idea is for a theme to have a
static-templates folder, with .php templates named after certain slugs. For example:
/about/ => /themes/foo/static-templates/about.php
/about/contacts/ => /themes/foo/static-templates/about-contacts.php
/foo/bar/baz/ => /themes/foo/static-templates/foo-bar-baz.php
/about/ is requested, you don’t need to worry about creating a page in WordPress, creating a new template and assigning it to your page. All you have to worry about is your /static-templates/about.php file.
Obviously if a page with that slug exists in the WordPress database, it’ll be loaded instead, so static templates have a lower priority, and there’s still that little overhead of trying to fetch a non-existent page from the database before a static template is invoked. It also does not (yet) distinguish between /foo/bar/ and /foo-bar/ requests.
Anyway, as I mentioned this is just an idea, and I would absolutely love to hear your thoughts about it.