(Reading time: 6 – 9 minutes)
I’m willing to take on updating this Thesis Custom Template code to 1.7 for $200. Here’s what’s in it for you:
- 5 options: with or without header, with or without footer, no sidebar, 1 sidebar, 2 sidebars
- 2 new sidebars you can use in your new templates
- Your byline as a sponsor for the expensive whitepaper resulting from this work.
Contact me if you’re interested.
Thesis 1.7 shows some nice refactoring in the frameworks code. It looks good. It does mean that the code in this article is relevant through Thesis 1.6. I’ll have an update for Thesis 1.7 soon, I have to update some client sites anyway. Sign up for the mailing list in this article, I’ll let you know when I’ve updated the code.
Note: I’m happy to help registered users of the Thesis theme when I can. Just point me to your account on the DIY Themes forum (you should have the link, right), we’ll take it from there.
Thesis theme for WordPress is an excellent piece of gear. What it doesn’t handle “out of the box,” it can be easily persuaded to handle with a minimum of fuss and bother. For example, custom page templates are not explicitly supported in Thesis, but are easy to implement, and I’m going to show you how.
The procedure requires 2 simple steps:
- Create the custom page template file
- Create the custom page template function
1. Create a custom page template file
Go to your thesis theme root directory, typically wp-content/themes/thesis151. You will see files named “archives.php,” “no_sidebars.php” and “custom_template.php.” Add your file there, say “cool_page.php.”
Add a single function to this file “cool_page();” It doesn’t really matter what you call it, but mirroring the file name makes it easy for everyone, including yourself, to see what’s going on. Here’s a source code listing of what that looks like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <?php /** * Template Name: Cool Page * * A custom template framework for creating pages with * wholly arbitrary layouts. DO NOT EDIT THIS FILE. Instead, * use the thesis_hook_custom_template() hook * to specify the contents of div#content_box. * Be sure specify which page should receive which code * by dividing your action using the is_page() conditional tag. * * @package Thesis */ cool_page(); |
NOTE: Make sure you change the name of the template on line 3 so it will correctly appear in your page template menu.
Sign up here so I can let you know when I get this code updated, thanks. By the way, if you’re finding this article useful, send an empty email to wp-weekend.customtemplate@aweber.com to get more useful tips, tricks, lessons on WordPress, news on security updates, etc. You’ll the get the cutting edge stuff a couple of times per month. It’s spam-free, privacy protected, yadda yadda yadda. You’ll have to confirm to get in; opting out later is an easy click. Just an empty email to wp-weekend.customtemplate@aweber.com does the trick.
2. Create a custom page template function
Now you need to add some code for rendering the page. Define the cool_page() function in custom_functions.php, and populate it using code you rip out of these files:
- lib/html/frameworks.php
- lib/html/content_box.php
- lib/html/templates.php
- lib/html/hooks.php
The easiest way to figure out what code to use is to print each of these files on paper, along with custom_template.php. Then follow the control of flow using a red pencil. Figure out which functions you want on your final page, circle those in blue pencil. Once you have it figured out, type it all in by hand. Actually, I just cut-n-paste, but I’m lazy and I’ve been programming long enough to follow it in my head… (is that a good thing or a bad thing…?). If you cut and paste, watch out for the “smart quote” problem.
Here’s what my code looks like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | /* MY COOL PAGE CUSTOM TEMPLATE */ // Function is called from wp-content/themes/thesis/cool_page.php function cool_page() { get_header(apply_filters('thesis_get_header', $name)); echo '<div id="container">' . "\n"; echo '<div id="page">' . "\n"; //thesis_header_area(); //thesis_content(); echo ' <div id="content_box" class="no_sidebars">' . "\n"; thesis_content_column(); echo ' </div>' . "\n"; echo '</div>' . "\n"; echo '</div>' . "\n"; get_footer(apply_filters('thesis_get_footer', $name)); } |
Some of the lines are commented out to show you where to put calls for various parts of the page.
Now, when you add a new page, you should be able to select Cool Page from your template selection drop down box on the New Page page.
NOTE: The function above produces an *extremely* stripped down page, no navigation. Don’t test it on a production blog. Here’s a screenshot:
If you’re a Thesis hacker, you should give this a try. It’s easy and fun!
Other solutions
There are other ways to do this, notably by modifying custom_functions.php and adding code to select page layout based on page ID or category, etc.
I find this clunky, and difficult to understand and maintain. Because the selection is done with numbers instead of logical entities (names), it requires looking up page IDs for every page you want rendered with the custom template, and modification each time you add a page using that template.
However, it does have the advantage of being “Thesis Portable.” That is, you only need to move what’s in the custom directory and nothing else.
Lagniappe
Just to be absolutely and thoroughly pedantic about literate programming, “thesis_get_header” from the source listing above really ought to be named “thesis_get_html_head” because:
thesis_get_html_headsays what it does.- The word “header” is overloaded and requires context to parse meaning. “html_head” means exactly one thing, no context required. Read “Head vs. Header — A critical difference for modifying WordPress themes” for in depth explanation.
- It confused me initially. I knew I didn’t want a header… but without including the head element of the html, I didn’t get any of the required CSS files controlling the page display.
It’s true about literate programming: elegance and good taste matter!
I run several websites using Thesis. If you’re serious about mastering WordPress, Thesis has a lot to offer, and I recommend—without reservation—that you purchase a license for your own use. Thesis has an excellent affiliate program as well, which you should join when you purchase your license.
Would you like more? Send me a letter...


{ 27 comments }
I have been looking all over and here is the gist of what I am trying to find.
I would like a template (code and where to add it) for thesis 1.5.1 so that I can add posts to my pages, other than my Homepage. I tried this one plugin and it kind of hosed my site and made the “page break” function no longer work even after removing the plugin.
So if you know of a plugin or code for a template to accomplish this could you please email me. Thank you so much!
I’m not really getting what you want to do, Ross.
One thing I have learned from over 15 years working with computers is this: if there isn’t a fairly easy straightfoward way to explain what you want to do, there probably isn’t any way to do it with your current tools. The solution is either use a different tool, or do something else, hopefully similar.
Look at the bigger picture. What, exactly, are you providing your readers?
Hi, I very much appreciate your alternate take on Berchman’s custom templates…you clearly have strong grasp of WordPress. I noticed in the DIY forums that you mentioned using an include in the custom_functions.php file and I’ve been contemplating a similar solution, but am not looking forward to banging my head into a steel beam for several days on end.
My goal has nothing to do with a custom template drop-down option, it’s simply to separate my code so that it’s easier to read & maintain. I imagine that by using an include within the the custom_functions.php file, one could generate additional files (ie. custom/user-header.php) which contain code & also reside within the /custom folder. Maybe something like this:
function user-header() {
if is_page('Example') {
include(TEMPLATEPATH . '/custom/user-header.php');
}}
The conditional would permit you to use this as a custom header on your ‘Example’ page…I imagine the same could be done for any page &/or any page section.
Then, in the custom/user-header.php file, you would include whatever code you want for your custom header, but you would need to be sure to add this as well:
remove_action('thesis_header','thesis_default_header')
add_action('thesis_header','user-header')
Alternatively, it looks like this may already be supported in Thesis using filters with these filter hooks: thesis_get_header & thesis_get_footer.
Sorry for going on, but I’d definitely like to get your feedback on this…one more thing, do you take freelance jobs?
Thanks in advance! …(1 for 3) I think this comment should be formatted correctly, sorry again ^_^
Yes, the formatted version is readable!
Your solution looks pretty good. My bias is to get rid of conditionals as much as possible. But I don’t know the WordPress codebase well enough to say much more. Most of my comments come from having a fair bit of programming experience. Certain ways of doing things keep coming up over and over and are more or less language independent.
I’m willing to consider freelance work. I’m very, very expensive for closed source code projects. Very. Open source or GPL projects that interest me, less expensive, possibly considerably less.
Thanks for the fast feedback! I’ll be working on this and will report back; although, it may be weeks from now…
Please forgive me if i don’t make sense. I would like to have most pages in my blog with a different design (not more than 60 pages with different designs on them). Do i have to use Custom Pages for each page. If Yes, will the custom_functions.php page get too long for my blog to work because i see that i have to add each custom page code to the custom_functions.php page. Please help me understand.
Any other solution would be GREATLY APPRECIATED
Sherwin, WordPress isn’t really what you want to use for that kind of project in my opinion. The strength of WordPress is that it allows you to easily create a large number of web pages with uniform appearance, not for creating a large number of web pages with all different appearances.
You may well be able to extend WordPress in this direction, but I wouldn’t use a huge custom_functions.php. What I would do is register callbacks to file handles for the appropriate page, then include it on the fly.
Really, I suspect what you are looking for is something that bridges WordPress and, say, Dreamweaver. I’m not aware of any tools out there covering that niche.
What is the information you are attempting to deliver, and to what market?
Have you tried rolling your own solution using perhaps Ruby on Rails?
Thanks for your QUICK response. What i am really trying to do is set up a website with different sales page for each item (up to 60 items). Now i would like the website to carry the same structural layout but the graphics, color schemes, header etc will only reflect the product being advertised on that particular page. I also want to include some CSS to change link and text colors as well. Its more like an affiliate site basically.
Yeah, WP doesn’t do that so well… Basically, you need to set up a structure outside WP, but in the WP directory, for handling sales and landing pages. You can add them to your sitemap.xml this way. You may be able to handle 404s using WP too, after you take them down. Not sure about that. Test it, let me know.
I have a post brewing on sales pages… or maybe it’s published. Poke around a bit. Can’t recall at the moment.Creating Landing And Sales Pages Side-By-Side With WordPress.
Dear Doctor, (caution: html-impaired, but unwilling to give up inches from the finish line).
My blog is WP with Thesis. What I want is basically a blank page template (for zero-distraction prod reviews/sales pages). Gr8 example at http://fitnessblackbook.com/ and http://fitnessblackbook.com/best-diet-plan/ respectively.
Created and ftp’ed “clean_page.php” to location as prescribed. Doesn’t show up in my edit page template choices. Have I missed a step or line of html code?
I have this html code for use with my hoped-for blank page:
[your content here]
It works fine if I use it in conjunction with the “no_sidebar” template, but leaves me with header and stuff. Is there a blank-page cure for one like me? Thanks a bunch in advance!
Beat
PS. Love your blog. Cool blurb to encourage visitors to sign-up for the newsletter – simple & creative!
here’s another attempt at that html code:
”
[your content here]
”
Beat Schindler´s last blog ..Dare!
one more try. replacing with &
¢er&&table border=”0″ cellpadding=”0″ width=”700″&
&tbody&
&tr&
&td&
[your content here]
&/td&
&/tr&
&/tbody&&/table&&/center&
Beat Schindler´s last blog ..Dare!
Make sure you have the name of the custom page template at the top of the comment section in that PHP file.
Dr Wordpress!´s last blog ..How Dangerous Are Private Label Rights To Your Blogging Credibility?
Thanks! I did it
now my page is very ‘professional’
No, Jonathan, you didn’t. This is spam. I looked at the source code for your linked site, and you’re not even running WordPress, much less Thesis theme.
Dave Doolin´s last blog ..World Class Copywriting: Are there Bird droppings on your catapult?
Hi Dr Wordpress…
I am hoping you can help me with a problem I am having implementing my own custom page using your code above.
Basically, I have followed what you have done to create a very simple page with one column and my header and footer.
I added the code exactly as you described above to custom functions. The code looks like this:
function cool_page() {
get_header(apply_filters('thesis_get_header', $name));
remove_action('thesis_hook_after_header', 'thesis_nav_menu');
remove_action('thesis_hook_header', 'add_social_links');
echo '' . "\n";
echo '' . "\n";
thesis_header_area();
//thesis_content();
echo ' ' . "\n";
thesis_content_column();
echo ' ' . "\n";
thesis_footer_area();
echo '' . "\n";
echo '' . "\n";
//}
}
/* Now we tell Thesis to use custom template */
// I don't think these are necessary... ???
remove_action('thesis_hook_custom_template', 'thesis_custom_template_sample');
add_action('thesis_hook_custom_template', 'home_pagecustom');
My problem is that the code it generates doesn’t have a closing HTML tag or closing Body tag so the page is broken. This is how the page HTML looks just before the closing body and html tags:
[snip]
Do you have any ideas at all?!
Thank you,
Tom
[12/11/2009: The listing is correct now -- Dr W]
Thanks Doc!!
That done the trick and saved me a couple of hours coding!! I managed to remove my custom footer as well.
David Frosdick´s last blog ..Google’s New Fade In Home Page
@David, glad you liked it! Watch for more in this space in the future.
Dr Wordpress!´s last blog ..Practical WordPress Tip #17: Use the tail of your Drafts queue for “notes”
Very helpful! This is exactly what I was looking for. I found this on a search engine, but I’m going go through your archives now!
Patrick Toerner´s last blog ..$1,000 a Month From a Minisite
There is a lot here… don’t get lost!
Or maybe, feel free to get thoroughly entrapped in the archives.
Dave Doolin´s last blog ..Hostest With the Mostest – Being a good neighbor on shared hosting
Hi! I’ve really enjoyed reading your articles on thesis, I just got mine maybe 3 weeks ago- I’m currently “working” on a new version of my blog (in the process of moving/making live from wp com to org)-
I am at the stage where I blow my blog up- I find I know what to put in, just not where!
Since I can actually semi-understand your articles (and THANK YOU for talking like a human), I was wondering if you might have any suggestions on a book? Is there a thesis book for dummies yet?
I have spent the better part of these 3 weeks constantly on-line, researching, but am scared to blow the blog up…again!
What is a completely technologically retarded person to do?
I have almost everything where I like it with the exceptions of custom pages (which I am STARTING to grasp) and making the header show a logo- (uhhhhhhhhhh duhhhhh).
Anyways, thanks again for your excellent articles! And if you have any suggestions for me, I’m desperate and would sure appreciate what ever you’ve got!
Thanks for stopping. It does take a bit of thought to translate this material, being appreciated makes it worthwhile.
Dave Doolin´s last blog ..The Fear – And Consequences – Of Failure
Hi…
I am a Thesis User. I would like to make a template without sidebar, without any images, without javascripts.Do You KnoW how to do that ?
Thesis has a built-in No Sidebar template that I use when I want what you’re asking for.
Dave Doolin´s last blog ..Doing It By The Numbers – Blog Post Engineering
thanks for sharing, I just learn how to improve my blog using thesis themes.. your thesis skin looks great

Rijal´s last blog ..Menjadi Spesial
Jen is right. In this case you would use thesis_hook_custom_template, which allows you to do whatever you want with everything between the header and footer. This is something that Thesis does differently than other themes, but I don’t think it is difficult, it just needs a bit of understanding of how the theme approaches things. Admittedly the documentation on how to is a little thin on the ground.
As I recall, thesis_hook_custom_template gives you one page template at a time. I wrote some test code to check it out.
What I’m doing here is a bit different.
Several months ago I went a dozen rounds of comments with someone who, as it turned out, didn’t actually read the article.
Not sure I’m going to stay with Thesis. 2010 theme looks pretty sweet, and it’s going to evolve quickly I’m sure.
Dave Doolin´s last blog ..Blog Post Engineering 072 ready to roll
Comments on this entry are closed.
{ 2 trackbacks }