Home ›› Thesis Tutorials ›› How To: Create a Custom Page Template

How To: Create a Custom Page Template

by Greg Rickaby on January 7, 2010

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.

{ 11 comments… read them below or add one }

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

Previous post:

Next post: