How To: Create a Custom Page Template

by Greg Rickaby on January 7, 2010

Post image for How To: Create a Custom Page Template

Custom page templates are the easiest way to make a whole new web design – inside of Thesis. Imagine, all of this space could be yours to code however YOU want…INSIDE of Thesis.

Use the blank space Luke...

In this tutorial, I’ll show you how to create a custom homepage template, while using a conditional tag and a little custom PHP code.

Step 1. Create a new PHP page and name it home.php. Upload it to: /wp-content/themes/thesis_16/custom/

Step 2. Open custom-functions.php and paste this at the bottom of the file.

// Remove Default Page Template
remove_action('thesis_hook_custom_template', 'thesis_custom_template_sample');

// Custom Page Template
function custom_homepage() {
	if ( is_front_page() ) {
		include (TEMPLATEPATH . '/custom/home.php');
	}
}
add_action('thesis_hook_custom_template', 'custom_homepage');

Step 3. Log-in to your WP Dashboard and click on Pages –> Add New

Step 4. Type “Homepage”, leave the content area blank, select “Custom Template”, and then click “Publish”

Step 5. Go to Settings –> Reading and check “A static page”, then select “Homepage”. Click Save.

Step 6. The Result:

The possibilities are endless here. If you’ve ever seen a Thesis design that DIDN’T look like Thesis, chances are they are using custom page templates.

UPDATE: 3/3/10

Here is a real-world working example of home.php below (See it live)

<?php echo thesis_sidebars(); ?>
<div>
 <a href="#"><img src="<?php echo get_bloginfo('template_url'); ?>/custom/images/multimedia-box.jpg" /></a>
 <a href="#"><img src="<?php echo get_bloginfo('template_url'); ?>/custom/images/multimedia-box1.jpg" /></a>
 <a href="#"><img src="<?php echo get_bloginfo('template_url'); ?>/custom/images/multimedia-box2.jpg" /></a>
</div>
<div id="news">
 <img src="<?php echo get_bloginfo('template_url'); ?>/custom/images/bar-1.jpg" /><br />
<?php
$category_box_1 = new WP_Query("cat=1&showposts=2");
while ($category_box_1->have_posts()) : $category_box_1->the_post();
$category_link = get_category_link('1');
?>
<div class="news">
 <div id="headline">
  <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
 </div>
 <div id="thumb">
  <?php the_post_thumbnail( array(100,100) );  ?>
 </div>
 <div id="excerpt">
  <p><?php the_excerpt(); ?>...<br />
   <a href="<?php echo $category_link; ?>"><?php $category = get_the_category(); echo $category[0]->cat_name; ?><?php $category = get_the_category(); echo $category[1]->cat_name; ?></a> | <a href="<?php the_permalink(); ?>"><?php echo thesis_teaser_link_text(); ?></a> | <a href="<?php the_permalink(); ?>#respond">Comments {<?php comments_number('0','1','%'); ?>}</a>
  </p>
 </div>
</div>
  <?php endwhile; ?>
  <h3><a href="<?php echo $category_link; ?>">Read More <?php $category = get_the_category(); echo $category[0]->cat_name; ?>...</a></h3>
</div>
<div id="flickr">
 <ul>
  <?php    if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar 1') ){ ?><?php } ?>
 </ul>
</div>

It’s calling for the Thesis Sidebars, creating a jQuery slide-show, and a sub-loop for the news box.

Related posts:

  1. How To: Create Additional Page Templates
  2. How To: Create a Sub-Loop in Thesis
  3. How To: Create a Featured Content Slider
  4. How To: Add Breadcrumbs without a Plugin
  5. How To: Get Featured Content Gallery to work in Thesis

{ 30 comments… read them below or add one }

O.C. Search Consulting August 11, 2010 at 18:26

Thanks for this technique, I’ve used it three time so far with no problems. I have one question though – My clients would like to edit their home page content inside the Wordpress admin and NOT by having to edit home.php. Is there anyway to apply this same technique but make the home page content editable from the WP administration panel (e.g. edit the “home” page)?

Reply

Greg Rickaby August 17, 2010 at 07:48

I wish it were, but it’s not possible using this technique.

Reply

Seo68 June 4, 2010 at 04:32

Nice post, i use it to custom my site
My Site:
D?ch v? SEO, Qu?ng bá Web

Reply

Justin Long May 13, 2010 at 12:58

Ok, this worked for me UNTIL I set the site as a whole to have a 2-column format. I want to have two different formats: the home page is my custom design (a specialized 3 column format) and then the post pages are a 2-column format. What do I need to change? My home page (http://www.justinlong.org) is shoving the third column on the bottom of the 2nd, trying to put the sidebar in.

Reply

Greg Rickaby May 21, 2010 at 07:19

Hey Justin – It won’t matter how many columns you make Thesis. The custom_template will always override and fill the entire width of the Content Box.

Reply

Nadav April 27, 2010 at 11:59

I love the tutorial. I have a question though. I want to use a background image that is 10px x 500px called bghome.png for the home page, and a different 10 x 500 images for the internal pages, called bgother.png. How do I put it into the CSS that the home page should used use bghome.png, and the internal pages use bgother.png as the background? Could I used an if then statement? This is a bit past my level of expertise. I don’t know how to code it. If you could help me out I would be forever appreciative!

Thanks,

Nadav

Reply

Greg Rickaby May 21, 2010 at 07:20

Use conditional tags! :) Copy & paste the code below into custom_functions.php

The code below says, “IF this is Page ID 2, then print home.css, ELSEIF this is Page ID 3, print about.css”. This will put a .css file in the WP_HEAD hook.


// Header Scripts
function header_scripts_html() {
if ( is_page('2') ) { ?>
<link rel="stylesheet" href="<?php bloginfo('template_url');?>/custom/home.css" type="text/css" media="screen, projection" />
<?php }	elseif ( is_page('3') ) { ?>
<link rel="stylesheet" href="<?php bloginfo('template_url');?>/custom/about.css" type="text/css" media="screen, projection" />
<?php }
add_action('wp_head','header_scripts_html');

Reply

Carlo April 26, 2010 at 09:32

Hi Greg, great tutorial. I followed it to a tee and it works, EXCEPT when I have my Feature Box custom code active. I placed a featured content gallery inside the Thesis Feature Box and when I display this the custom template won’t show up on the home page. When I comment out the add_action to place the content gallery in the Feature Box hook, then the custom page will show up. Is there some sort of conflict?

This is the code for the custom feature box:

function custom_featurebox(){
if (!is_page(array(1150,1268, 1259, 1264, 1260))) {
global $post;
include (ABSPATH . ‘/wp-content/plugins/featured-content-gallery/gallery.php’);
}
else { ?>

<?php
}
}
add_action('thesis_hook_feature_box','custom_featurebox');

Any help would be appreciated! Thanks.

Reply

Greg Rickaby April 26, 2010 at 18:52

Great comment, have you tried placing it in thesis_hook_before_content instead?

Reply

Carlo April 27, 2010 at 09:04

You mean the featured content gallery? I actually used to have it in thesis_hook_before_comment (before I tried making custom templates) but I had a need to move it to the Feature Box…because I need to swap the FCG with smaller, static images on different pages…and by putting it in the Feature Box it resized automatically to the size of the image…whereas this wasn’t happening in the before_content hook…also I was having a problem positioning the smaller images for some reason.

I will try switching the hook, just to see if that makes the difference. If it does, any tips on how to make it do what I want it to do outside the feature box?

Thanks for your time!

Reply

Carlo April 27, 2010 at 10:11

Hi Greg,

I just tried switching hooks and it made no difference. After switching to before_html I again commented out the code and the template then shows up. So it looks like it’s definitely something in the FCG code.

Reply

Greg Rickaby April 28, 2010 at 08:17

FCG is a hunk-o-shit. It’s still only Wordpress 2.7 compatible. Did you try my other tutorial on how to make your own Featured Slider? http://gregrickaby.com/2010/04/how-to-create-a-featured-content-slider.html

Reply

Carlo April 28, 2010 at 09:42

Really? I’m running 2.92 and it seems to be running fine. I might give your tutorial a try though if I run into problems with it. Since it’s working OK now I have so many other things I need to dedicate time to.

By the way, I got the template working! I changed the function in custom_functions.php a little…replaced “else” with an “else if” statement and just specified each page. Also changed the !is_page and went with is_page() || is_front_page().

Seems to like this now. Thanks for your replies! Great site.

Reply

Greg Rickaby April 28, 2010 at 09:47

God Bless conditional tags, good work…this is what being a Thesis “Pro” is all about.

Reply

Barbara D April 16, 2010 at 16:43

Got it! Great! Thanks a bunch. This was so clear and easy.

Reply

Trisha April 7, 2010 at 20:28

Been through a dozen of these tutorials, yours was the first to work. I created a custom blog page, just switched out every instance of ‘home’ with ‘blog’ and it worked! Now just have to figure out how to feed the content, make custom sidebars and switch the header graphic. Baby steps :) THANK YOU!

Reply

Greg Rickaby April 8, 2010 at 09:21

You’re welcome!!

Reply

Tim March 13, 2010 at 16:57

Greg,

I am a first time visitor to your site and based on your tutorial I have not only bookmarked your page, but took a HTML/CSS book for Dummies back to Barnes and Noble. Your instructions were fantastic. I am a newbie to the webdesign world so thanks again for such great instructions

So now I have a blank homepage. I have uploaded a file that I would like to use on my homepage. It is a file to create an ask campaign what I don’t know what to do is where I should actually put this file. I currently have it in my customs file, but I think I am supposed to put it somewhere else so that it actually executes something.

Reply

Greg Rickaby March 14, 2010 at 09:42

Tim,

Your newly created custom coded file, should go inside of /custom/.

Don’t forget Step 2…you have to call for it inside of custom_functions.php.

Reply

Jordan March 2, 2010 at 21:16

Greg,

Beautiful! I really like it. I have one specific question, and a general inquiry.

Once the new homepage template is in place and selected as the one to control front-page, when I go back to the Thesis design options panel and change the site layout options (specifically column widths for a 3-column scheme) to these changes affect the newly created template or only (as I very much hope…) the remaining pages?

Here’s what I’m trying to do: Create a different layout for a) homepage and b) all other pages, where the differences between the two classes of pages are limited to:

1. Different column widths – “a” is one and all b pages is another fixes set of widths.
2. Content: Back pages perform their traditional functions (i.e., post, page, archive, search), all taking place in the respective content columns. However, the material that goes into the 2 sidebars of all “b” pages is different than the material that goes into the homepage sidebars.

Based on my limited knowledge of php and WP, if your solution above separates the newly created homepage template from the controls of the Thesis design options panel, then I have a way of creating the two layouts I’m looking for:

1. Thesis design options for all back pages
2. The new homepage template, w/ css code for columns and area design.

Is this how you’d suggest going about this task? Would you have some coding suggestions on aspects of this that might not be fully covered in your excellent tutorial?

I know that this is a rather long discussion… I hope you get a change to respond, however briefly.

Many Thanks!
Jordan

Reply

Greg Rickaby March 3, 2010 at 08:25

See above, I added some real-world working code. This should answer all your questions!

Reply

Jordan March 3, 2010 at 10:41

Greg,

Thanks for replying and you got my vote on the Montana website :-) It’s very well organized and the message comes across nicely!

I’m afraid I’m not quite there with php to see the ‘big picture’ applicability to what I’m trying to do – I understand some of the individual pieces, but not how I can apply the logic to my task.

Could you tell me please whether the *column-structure* of the product of your custom page template (the subject of this tutorial) ends up being controlled by the Thesis design options panel, meaning the default site layout, or does it become an independent page with its own layout settings?

I’m still not sure how to create 2 different page structures. Yes – I saw that the Montana candidate’s news page consists of 3-col while all other pages have two only. But I’m not following the code well enough to see where it’s done…

And, if you can take the time to address the overall question – how would you go about (“big picture”) addressing what I’m looking to do?

Thanks again!
Jordan

Reply

Ava March 1, 2010 at 11:07

Excellent tutorial and easy tutorial. Thanks!

I did this and it works. Sorry about the newbie question but…since edits are done via the newly created home.php for a static home page:

1. I read in the Thesis forums that in order to set meta descriptions/titles for a static home page, I’d have to use the “Edit Page” option within Wordpress to insert them rather than use the “Thesis Options” panel.

But since I’m using the home.php file to insert my html (rather than using the wordpress “edit page” to do that), where would I/how would I insert the meta descriptions and titles?

Thanks again!

Reply

Greg Rickaby March 1, 2010 at 11:59

The HTML that you’ve created for home.php, only goes in-between the header and footer. To change your SEO options, go and edit them in the WP Dashboard as normal. All home.php is doing is canceling out what you would put in the content box.

Reply

Ava March 1, 2010 at 12:45

Thanks Greg! That was fast and so helpful! *One less thing for me to stress about*

Reply

Andy January 11, 2010 at 01:49

Just what I was looking for – thanks

Any ideas how I’d remove the sociables from the bottom of the custom template? I want to leave them on for the blog.

Reply

Greg Rickaby March 1, 2010 at 12:00
Loren Nason January 8, 2010 at 23:26

Thank Greg

Never thought about making custom templates that way

I only thought about making the template and ALL the code for the template was put into the custom functions file

Reply

Neil MacLean January 7, 2010 at 22:27

Excellent tutorial, thanks Greg. And very easy to follow.
I always wondered though, how do you create different custom templates if you don't want to change the home page?
I'd like to save a few different pages in the custom folder to choose in the template drop down menu.
I used to do that with Revolution but I've never known how to do it with Thesis.
Many thanks

Reply

Greg Rickaby January 7, 2010 at 22:43

That tutorial is next! :)

Reply

Leave a Comment

{ 1 trackback }

Previous post:

Next post: