Thesis Tutorial: Multiple Custom Page Templates

February 25, 2009 · 431 comments

in Articles,Internet,Technology,Tutorial

thesis-binary

I have been working with Thesis for a little over a month now. Thesis is a relatively new templating platform for WordPress. Thesis has unmatched SEO, cross-browser compatibility, and top-notch HTML + CSS architecture. This website runs on Thesis.

I was looking through the Thesis forums and tweeting with others on how to get a solution to an issue. The issue has to do with creating custom templates. I want a custom home page design. I also want a custom template for other pages. Basically I want multiple custom templates available under one design. I have tried to explain what I have found below. I welcome your comments and ideas. There may be other ways to do this (usually is) but here is how I did it. Hopefully this can help others.

A Little Thesis Primer

If you are familiar with Thesis you can probably skip to, “Getting To It.” The way Thesis works is to keep all customization inside of one folder–that is part of its genius. Whenever the templating system is updated you overwrite the entire file structure, save your custom folder, and replace that back in and voila you have arguably the best templating system under the hood while keeping your design in tact. This may not seem like much to the layperson, but for those of us that design and develop web sites on platforms like WordPress it is a godsend.

So back to multiple custom templates inside of Thesis.

All of the custom files sit within one folder in ~/wp-content/themes/thesis/custom/

Image of folder structure of where custom files sit inside Thesis

Every customized design using Thesis has their custom templates, css, and images stored within this folder.

To create custom page templates you need to use Thesis’ ingenious “hook” system that allows you to tinker with the components of any part of the standard layout or, if you are brave, roll your own layouts and custom designs. The best entry-level instruction I have found for understanding and using “hooks” is at the web site of Sugarrae: here it is.

Once you have the basic understanding of “hooks” under your belt, have your designs ready to go, and have some WordPress chops, you are ready to create multiple custom page templates.

Getting To It

First thing you need to do is make sure you have your “home page” set to really be the home page. Whenyou are logged in as the admin go to settings/reading. “A static page (select below)” should be set to your homepage. See this image:

homepagesettings

Once I have done this I then need to make sure I have selected the “Custom Template”option from the drop down menu on the right side when you are editing any page (not posts!):

picture-2

So, first I want a custom home page template.

In the file thesis/custom/custom_functions.php I added:

/* HOME PAGE CUSTOM TEMPLATE */

function home_pagecustom() {
/* check to see if homepage. has to happen inside the function */
if (is_home() || is_front_page())  {
?>
...Your custom layout goes here...
<?php } }

/* Now we tell Thesis to use the home page custom template */

remove_action('thesis_hook_custom_template', 'thesis_custom_template_sample');
add_action('thesis_hook_custom_template', 'home_pagecustom');

The code above has been whittled down to show only the essential code. It works to display a custom home page as long as you have selected “custom template” from the pulldown menu when editing the ‘home’ page.

You may insert any HTML and style it in the custom.css file. Be sure to save custom_functions.php and custom.css and upload to your ~/wp-content/themes/thesis/custom/ directory.

One Custom Page Down.
How About A Second?

So how do you add another custom template after defining the home page template?

You need to define another function for your next page template. You can add as many functions (think page templates) that you like. Each one needs a unique name. You also need to define the conditional properly. You need to make sure that the conditional is within the function—it will not work outside of it.

Use the right *if* statement to make sure you apply the right template to the right page. I typically put the page tag and the page ID—a type of insurance. You can find a page ID by hovering your mouse over the link to edit the page when viewing a page list within the admin area of WordPress.

This example below is testing for the “press page” and if it is, puts the WordPress content on the left side of the page and both sidebars to the right:

/* CUSTOM PRESS TEMPLATE */

function new_presspage() {
if (is_page('press') || is_page('512')) { ?>

<div id="content">
<div class="post_box">
<div class="headline_area">
	<h2>Your Headline</h2>
</div>
...This is where your content goes...
</div>
</div>
<div id="sidebars">
<?php thesis_build_sidebars(); ?>
</div>		

<?php } }

add_action('thesis_hook_custom_template', 'new_presspage');

Since you already invoked the “remove_action” on the ‘thesis_hook_custom_template’ in order to replace the home page first you do not need to repeat it.

The example above looks exactly like the standard content column on the left with dual sidebars on the right. I used a custom template in this instance because I wanted to perform specific calls to the database and produce specific lists of posts. Since I am doing it this way I also create the ability to style the page however I like through the use of creative CSS implementation.

Wash, Rinse, Repeat

You could then repeat the code above and apply it to any number of specific custom templates you would like. All you need to do is

  1. create a unique function name
  2. reference the right page in the conditional
  3. make sure conditional is within the function
  4. place whatever content you would like within the proper divs
  5. style the content within the custom.css file
  6. make sure your page within WordPress has the custom template selected as its template option
  7. test, test, test

That’s it. This tutorial should get you well on your way to creating multiple custom page templates within the single custom_functions.php file. If you have any questions, comments, or suggestions I welcome them below.

Hope this helps.

Do you need help with Wordpress, or the Thesis theme?

Image of DoubleMule certification. I'm a Thesis Certified Designer.

If you are a web designer or web developer needing help, or a 'do-it-yourselfer' looking for a professional Internet presence I can help.

If you need help with a specific WordPress or Thesis theme issue or a complete website, I offer consultation, complete web design, and web development services.

Get in touch and we can talk about your needs and start the process.

  • msc

    “You asked where to find source code that is being used for the pages. You can find it in here.”

    Was there a hyperlink to a directory in this sentence?

  • Rebecca

    Thanks for this tutorial and all the helpful information on this site. Question: Can I create a custom page template for my About page without first setting my home page to a static page? I want to keep the home page dynamic (dynamic listing of latest posts in #content with two sidebars of widgets and custom ads). I'm trying to create an About page that has only the content added from the Pages panel and has a single sidebar with unique content (client quotes, etc.). I've been trying to do this following your instructions above, but so far, it's not working. Thought before I fiddle around further, I should check to see if it's because I don't have a static homepage.

  • http://www.facebook.com/adamjblust Adam J. Blust

    I would also like to add a template choice in the template dropdown, like jvgreene2 said. Can that be done? I’m trying to make choosing templates easy for non-technical users of my site.

  • http://www.mylicindia.com LIC india

    To be frank I am not coder and these steps goes nowhere for me… :(

    how much a coder will charge for customization?

    pls email me

  • Dean

    I’m really struggling here…

    I want to create 15 pages in Thesis for my reviews. As all my reviews are done in HTML/CSS I just need a blank page template from Thesis.

    How would I create this blank template, I followed another guide to do this for my homepage…

    Could I use this same blank template for all 15 of my review pages?

    I’m totally confused :)

  • Pingback: Thesis Tutorial: Sidebars However You Like Them — berchman.com | Geek is a Lift-Style.

  • http://coloncleansehomeremedy.muslimblogs.com/ colon cleanse

    wow…this is interesting tutorial…very helpful for me..

  • Adam

    I have been working with your code, and the custom home page works like a charm. For some reason, I cannot get the second custom template to work, the pages will appear without the default template, but none of the html for the custom template shows up. I think I am referring to the page incorrectly, can you provide more details on the if (is_page(‘ ‘) portion of that process? Thanks.

  • http://www.theblueprintproject.info/blackedition/ the blueprint project

    this is a great article i love reading the content on this site

  • Stevek1921

    This is a great post! Maybe because it’s really late, or because I’m not good at code… probably the later…;o) In any event, I followed the tutorial and attempted to paste my HTML into the section that says, ‘…..Your custom layout goes here…’

    And now my home page (which I want to create as a squeeze page) says, ‘..Your custom layout goes here…’.

    I even tried to add some Custom.css but I’m sure that is wrong as well. Any help would be appreciated. Thanks!
    Steve

  • Stevek1921

    Ironically my page now loaded…. So.. thanks again for the great tutorial! I just need to do some tweaking on formatting and fonts, but I think I can manage. Sorry for the confusion.

  • http://modificationzoom.com mortgage loan modification

    Wow that’s very outside of the box; I gotta tip my hat for originality but a simpler method would be to simply grab the div id or class and use css’s display:none :)

  • http://modificationzoom.com mortgage loan modification

    Oh and one last thing! A quicker message for “recycling” or using these custom page templates throughout your site is to not assign them as a custom page template. Let’s say on your home page you want to display a featured area, but the rest to stay the same, and you want to add a featured area to 13 different pages – but with the lower content staying the same, simply write out your featured area, test for the page, and insert it using hooks to the appropriate location. Hopefully this will help people move from rinse, wash, repeat, to simply rinse and repeat ;) Happy coding!

  • http://flockpost.com/ Puneet Sahalot

    Hey Berchman,
    Thanks for the great post! This is what I was looking for. Just a quick question, will the custom template let me handle everything ? I mean, can I hide the default thesis stuff like sidebars, content box, footer ? I have complete code with me for the home page layout which I would like to use for home page instead of the default thesis layout. Is this possible ?

  • Anonymous

    yes this is really very helpful.

  • Pingback: How to add custom sidebars to a page in Thesis 1.7 | Thesis Theme | Wordpress Themes

  • Dan

    This is a great tutorial, and I did manage to create a custom home page with this, but I’m having one little problem.

    The custom home page I created as two equally-wide columns. I created and added the two styles to custom.css, then added the custom home page template to custom_functions.php. The two columns appear nicely, but the footer doesn’t want to clear both columns. Instead, it seems fixed about about 520 pixels below the header.

    Any idea as to what I’m doing wrong?

    Thanks, Dan

  • Joshua

    Hey, great post! I’ve already created a bunch of page templates. I also created custom sidebars for each page, so I’m not using the thesis build sidebars function. However, I don’t get my multimedia box above the sidebar, how would I go about doing that? I tried looking briefly for the function to build the multimedia box, but decided I would just ask you.

    Thanks!
    Joshua

  • Harish

    you saved me hours of research work. Thanks so much :)

  • Pingback: How to add custom sidebars to a page in Thesis 1.7 | Thesis Theme | Wordpress Themes

  • Pingback: 6 Great Thesis Tutorials for Noobs

  • http://www.signsfunny.com Funny signs

    It’s my bad I haven’t come on this site before.  Only when I’m having problems with my blog I’m coming to sites like this.

  • Defalcator

    this is simply awesome,love your tutorials about customizing of the thesis framework

  • http://www.thewordpresszone.com/ Gouri

    Thanks for such a detailed tutorial..

  • anne pouch

    Great tutorial but when you use custom templates it no longer is possible for most users you maybe building a site for to update the site themselves without teaching them HTML/CSS , ftp, custom_fucntions.php, etc.  correct?   How do you handle this with content you want clients to be able to update easily?

  • Berchman

    Hi Anne,
    Typically when I build any fully custom solution I will do a video tutorial that I provide with the project. That way you can watch me publish/edit/delete using the tools within WordPress and your custom template.
    Let me know if you have any questions.
    Thanks,Bert

  • Pingback: 20 Awesome Thesis Theme Tutorials from 18 Different Thesis Sites

  • Paul Chamberlain

    Ugh – I just figured my problem out – I needed a posts_per_page=-1 in there. That one always gets me!

    Thanks anyway!

    -Paul

  • http://www.berchman.com berchman

    Paul,
    Glad that you figured it out.
    Thanks,
    Bert

  • http://justen.us Justen Robertson

    Thanks, just what I needed to know.

  • Pingback: Top Resources for The Thesis Theme on WordPress | Daniel McClure

Previous post:

Next post: