Thesis Tutorial: Multiple Custom Page Templates

February 25, 2009 · 445 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.

  • http://www.portraittutorials.com/ Brandon

    Are your saying, how can you make a template for thesis that will post, posts under a certain category in a page by using a page template? Because I have been trying to figure that out for a couple days now so I can put it on my blog. I can let you know when I do unless someone else knows how.

  • jona_than

    Thanks for your help. This is a very helpful tutorial for me

  • http://twitter.com/lymanreed Lyman Reed

    Just wanted to drop you a big thank you for this tutorial. I just picked up Thesis a few days ago, and this really helped me to understand some things that I wasn't getting. So… thanks!

  • marcoryan

    If you wanted to have the template identical on 2 pages except say for a slideshow in the header which appeared only on the home page, and then a single image that appeared on the other pages, how would you code the Else statement – something like this?

    function custom_header() {
    if (is_home() || is_front_page()) {
    ?>
    HOmepage HTML here
    <?php }
    else {
    ?> Alterntave HTML code here
    <?php }
    }
    …Your Custom homepage layout goes here…
    <?php } }

  • http://www.berchman.com berchman

    You need to create an empty page in WordPress with the title of 'Blog' then publish it. Go back to 'Reading' and you should be able to select 'Blog' from the dropdown menu.

  • http://www.berchman.com berchman

    You make the conditional check for the homepage only, then deliver your custom page template. Then in the WordPress/Thesis options you set your default pages to take on the sidebars how you like. Hope this helps.

  • http://www.berchman.com berchman

    Thanks Travis. If I understand you correctly you want posts to use a certain custom page template. You should be able to create a conditional that tests for the correct category ID and then deliver the proper template.

  • http://www.berchman.com berchman

    Marco I would take these two things separately. I would create a function to test and deliver the proper header area, then in the custom page template I would call the function to deliver the right header. It's nested functions. Hope this helps.

  • http://www.berchman.com berchman

    Lyman you are very welcome. Glad it helped you out.

  • http://savetheface.org/ Wendy

    Hi,

    Thanks for your useful tutorial. I am trying to make the home page a magazine style layout which I can click to pages in behind. I did try to make the home page a static page but it seems like the sidebar widgets are all gone and I have to code the home page in html. Is there a better way to do this?

  • ireey

    You have great tutorial and I am glad to paid a visit here. Can you please help me on my problem? I am currently designing a website using Thesis, is it possible to make a certain page (Blog) stand out in the nav menu in bigger letters? Also, is there a way to upload the image without using the URL? I want to know how? Thanks in advance!

  • mel

    I've used your tutorial to create a custom home page that uses a jpg containing the logo. The image does not appear when I view the page. What path should I be using in <img src … to bring in the image?

  • Graeme Mac

    For the home page only I'd like to remove my category navigation.

    I am trying to use:

    function home_pagecustom() {
    /* check to see if homepage. has to happen inside the function */
    if (is_home() || is_front_page()) {
    ?>

    <?php remove_action('thesis_hook_before_content_area', 'category_area'); // Input Category Area ?>

    // Custom HTML Here //

    But it's still pulling it from the loop before this code executes.

    Any help would be appreciate.

  • Thesis Junkie

    How do I use a custom page template for the blog page (it is a static page)? It always defaults the standard page layout? Thanks.

    I have been able to create custom templates for all other pages.

  • http://khmerbird.com/ Santel

    i follow your great tutorial and i get it works on some of my page. but can we do the same thing on single post page? i tried various ways but not yet figure out how to define a custom template for single post.

    any advice?

  • Karley

    Great tutorial. I didn't realize you needed to create separate functions for the other pages. Instead of hard coded the content how would you bring in content that has been entered in the page editor.

  • Pingback: The Ultimate Guide of Tutorials and Resources for Thesis Theme Users

  • http://www.berchman.com berchman

    You would need to pull in “the_content()” from the correct page or post.

  • http://www.berchman.com berchman

    You need to base it on the post ID. FInd the post ID number and use that in the conditional.

  • Pingback: Thesis Tutorial: Multiple Custom Page Templates — berchman.com | WpMash - WordPress News

  • zbychxxx

    thanks for the great info. However i would love to see second part of this tutorial. Like someone else asked above: how would you bring in content that has been entered in the page editor. the_content() seems like only for coders suggestion :)

    what if i want to create a custom template that still works with functionality of WP. So i could still use page editor, widgets and all that without editing custom_functions file. Is there a way to know what's my current Thesis template is in terms of php template code structure so i could use it in “…Your custom layout goes here…”??

    thanks!

  • Brigitte

    I'm about to start a new website and I'm wondering if I should give Thesis a go. I have always designed my sites in Dreamweaver and done all the SEO I can do.
    If I try Thesis, am I going to simplify my life or complicate it by learning a new system from scratch that won't do more than what I can already do?
    Any feedback would be appreciated. Thanks.

  • Amanda

    Hello! I'm trying your technique of setting up a custom page template, and I'm stuck on something.

    Would you be able to explain the basic methodology for removing or changing something that's already on the page?

    For example, I have a custom nav bar (made of images) that I have placed below my header using the “after_thesis_header” hook. For my custom homepage, I want to add an additional image between the header and my nav bar images.

    I think I'm missing something obvious, but I'm not sure how I would do this. I don't understand how we can alter existing design elements to get them to look different/be arranged differently in a custom template.

    Any help would be much appreciated!

  • Mikkel

    Hi Lisa, you can just configure thesis to not show a 'home' link, and then add a custom link of your own to the menu, call it 'Home' or whatever, and link it to index.php

    this can all be done using the thesis admin panels with no custom coding required.

  • http://www.tanmoy.net S K Tanmoy

    Great Tips. But I wanna use a fully separate static page. Is it possible

  • Pingback: Top 25 Thesis Tutorials for Newbies

  • Pingback: Creating A Squeeze Page With Thesis – Part One – Thesis Tutorial

  • Anonymous

    First of all, a huge thanks for making this topic clear. I’ve been stuck for a while and after reading your post, I at least got started. However, I’m still facing some issues and I’d greatly appreciate if you could please give me some more pointers as I’m still very new to Thesis.

    We’re a non-profit with most volunteers not very tech savvy. So what I’m trying to do is use the blog to populate rest of the website. For example, if someone posts a blog under video category, I want that post to pop up on the Videos page.

    I followed your example and wrote this:

    /* CUSTOM Videos TEMPLATE */

    function videos_template() {
    if (is_page(‘videos’) || is_page(’11′)) { ?>

    Videos

    <a href="” rel=”bookmark” title=”Permanent Link to “>

    <?php } }

    add_action('thesis_hook_after_content', 'new_videospage');

    The site is http://www.ProjectHealthcare.org

    Thanks again for a great post and I hope I can implement it correctly.

  • Mike

    Hi, thanks for the tutorial. There's a couple things I'd love to know.

    1) Can you still use the SEO options Thesis gives you for pages with these custom templates?

    2) What's the difference between this way of creating custom templates and the one at gregrickaby.com?

    a) do one of these ways work better with a higher # of custom templates (like say 5+)

    Thanks!

  • Pingback: 47 Customizations for the Thesis Theme

  • http://twitter.com/thechrisjordan ? Chris Jordan ?

    Awesome summary. Many thanks for sharing. I've been using Thesis for 7 months or so, but just now really getting into some higher level mods… This is great

  • Jan

    I've read you post and the comments several times. I don't understand php at all. What I'd like to do is create a custom template that's simply a blank page – no header, no navbar, no sidebars, no footers. Just blank pages to run videos from. Possibly a Title on each. Is this possible? If so, how do I code the custom_functions.php files to remove all the stuff I don't want?

  • Jan

    I've read you post and the comments several times. I don't understand php at all. What I'd like to do is create a custom template that's simply a blank page – no header, no navbar, no sidebars, no footers. Just blank pages to run videos from. Possibly a Title on each. Is this possible? If so, how do I code the custom_functions.php files to remove all the stuff I don't want?

  • Pingback: Ultimate Thesis User Guide

  • http://www.berchman.com berchman

    Hi, I visited your site and it appears that the video page will not load at all. Can you tell me what you have done?

  • http://www.kimandjason.com Jason of Kim & Jason

    I'd like to create a template that affects every page that is a child of a specific page. Is this possible without having to call every single page in the conditional statement. This is what I've tried, but it doesn't work:

    if ( is_page('9832') || is_page('9830') || $post->post_parent == '9830') {

    What am I missing?
    Thanks!

  • http://www.kimandjason.com Jason of Kim & Jason

    I'd like to create a template that affects every page that is a child of a specific page. Is this possible without having to call every single page in the conditional statement? This is what I've tried, but it doesn't work:

    if ( is_page('9832') || is_page('9830') || $post->post_parent == '9830') {

    What am I missing?
    Thanks!

  • http://pulse.yahoo.com/_ROFXEO3XFKVJ6REQFGLR2N7NQU ladoomal g

    You have very clearly mentioned this is for pages but all my content is for posts and I wanted to double check if I can use this with posts too before I dive in for good

  • http://pulse.yahoo.com/_ROFXEO3XFKVJ6REQFGLR2N7NQU ladoomal g

    HI,
    I am also looking to use custom templates on posts. Were you able to find a way to get this done ?

    Cheers,
    Vishal

  • http://pulse.yahoo.com/_ROFXEO3XFKVJ6REQFGLR2N7NQU ladoomal g

    oopps just saw berchman has answered this already

  • http://pulse.yahoo.com/_ROFXEO3XFKVJ6REQFGLR2N7NQU ladoomal g

    I can't seem to find the custom template option for posts in wp 3.0 thesis 1.7

    Is there something I am missing ?

  • http://pulse.yahoo.com/_ROFXEO3XFKVJ6REQFGLR2N7NQU ladoomal g

    I have the custom template option for pages but they are not there for posts any advice will be much appreciated

  • Manu

    I undestood a little bit but not everything.
    All I need is an image that shows up when you go to the website, and click on it to enter the main blog…Is that possible? Many thanks

  • http://twitter.com/funwithmama Nadia

    do you by any chance have a tutorial on how to create a category page that shows an excerpt of each post(including a picture)

  • jvgreene2

    This is a great post and has helped me tremendously. What I really want to do now is to add another permanent template that I can choose from the drop-down with the other options (Default Template, Archives, No Sidebars, etc.) that looks a little different and maybe has a different header that I can choose on a page by page basis without specifying each page id in the custom_functions.php. Is that possible?
    Thanks

  • QuantumGood

    Any thoughts on whether this would apply to Genesis (StudioPress) generally?

  • http://www.lifewithoutpants.com Matt Cheuvront

    Great tutorial here buddy – thanks for putting it together!

  • Dev

    Thanks a lot! This helps a ton!

    I am trying to take this a step further. There's some code I want to keep static through all pages (styling) So I am including it in the custom_functions.php file. But at the same time I'd like that the actual text content for the page is populated from my WP pages. Is there any special WP keyword I should add for this?

    Thanks again!

  • Dev

    Never mind, figured it out! Again, thanks a lot for this post. It helped a lot!

  • http://greenyourdecor.com Jennae @ Green Your Decor

    Is there a way for me to remove the header and nav menu from a custom page template? I imagine I would do that with a “remove” hook, but I'm not sure where to put it in the function. Thanks!

Previous post:

Next post: