Add a Custom Page Template to WordPress Thesis Theme
Thesis is a popular premium WordPress theme. Unlike many themes that are implemented to plug directly into the WordPress-defined template structure, Thesis is a force unto itself. It’s a framework that completely redefines the approach to WordPress customization. It achieves this by supplying a rich set of hooks into the various stages of the page generation process and then creates one location where all customization code goes. One file – custom_functions.php – holds all the custom code and is safe from overwriting during theme upgrades.
The Thesis framework is sufficient for a wide range of customization needs. However, as with all popular software, users’ needs eventually go beyond the default capabilities of the software. Thesis has in-built support for creating 2-column and 3-column sites. The layouts are configured via the Design Options menu and apply site-wide. You can override the layout of particular pages (eg home page) by intercepting the page generation process in custom_functions.php. The problem with this approach is that you have to know the designation (home), name or id of the page before-hand as you customize the site. If these details change after the site has been launched, then the customization code is going to break.
What if you want to alter the layout of an arbitrary number of pages that are going to be created in the future? All you know at customization time is what the layout shall be, but not which particular pages shall use it. This obviously calls for a solution that does not involve updating the customization code every time a page requires the custom layout. Even better, it calls for a facility that can be triggered while the page is being created by the user. A facility such as the WordPress page Template selection drop-down. If you could create a custom template and have it selectable on the Template drop-down, then the user would simply pick it during page creation (or editing) and have it used for page rendering.
Thesis (version 1.6) does not support plugging in of custom template files, but it is flexible enough to pick them up if you know where to tweak. Here’s how you go about doing exactly that:
1) Problem description
The hypothetical site we shall be working with is a travel blog. The site has various sections, but the one that is of interest here is one called Places. It has pages describing various travel destinations. These pages have advertising that shows in the left column. Every other type of page on the site does not have this left column and therefore no ads showing. How do we get the ads to show on the Places pages, but not on any other page?
2) Create the page template file
The Thesis theme has a convention, where customization code is stored in the /wp-content/themes/thesis/custom/ folder. The standard customization files in this folder are custom_functions.php and custom.css for code and styling respectively. This is the folder where you shall put the new custom template file places_template_functions.php. The code for the template file is:
<?php remove_action('thesis_hook_custom_template', 'thesis_custom_template_sample'); add_action('thesis_hook_custom_template', 'places_page_layout'); function places_page_layout () { if (is_page()) { global $post; $places_template = get_post_meta($post->ID, '_places_template_swapped', true); if(!empty($places_template)){ ?> <div id="places_page_content"> <div id="sidebars"> <?php places_ad_column(); ?> </div> <?php thesis_content_column(); ?> </div> <?php thesis_sidebars(); ?> <?php } } } register_sidebar(array('name'=>'Places Ads', 'before_title'=>'<h3>', 'after_title'=>'</h3>')); function places_ad_column(){ ?> <ul class="sidebar_list"> <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Places Ads') ){ ?> <li class="widget">Place ads here</li> <?php } ?> </ul> <?php } ?>
The function places_page_layout ()
confirms that the current page is using the Places Template and then inserts the ad column into the page by calling places_ad_column()
.
3) Create the template placeholder file
The placeholder file has two roles:
i) Register the new custom template in WordPress
ii) Call on Thesis framework to generate the Places page
The place holder file shall be located in the folder /wp-content/themes/thesis/ and called places_template.php. The code for the file is:
<?php /** * Template Name: Places Template * * A custom template for use with Thesis theme for creating pages that add a left sidebar. * DO NOT EDIT THIS FILE. Instead, use the thesis_hook_custom_template() hook in custom/places_template_functions.php * * @package Thesis */ thesis_html_framework(); ?>
The text Template Name: Places Template
is key since it informs WordPress what the new template is called. The template is now listed in the WordPress page editor.
4) Load the new template into Thesis
The files that are in place so far enable WordPress to list the new template in the page Template drop-down. However, the template code is inaccessible since has not been loaded. The loading of the template code is accomplished by piggy-backing onto the Thesis custom_functions.php file. Add the following code to the end of the file:
if (file_exists(THESIS_CUSTOM . '/places_template_functions.php')){ include(THESIS_CUSTOM . '/places_template_functions.php'); }
5) Override Thesis custom template handling
Thesis is not aware of the new template and therefore cannot invoke it when a Places page is opened. To remedy this, we have to add code to the file places_template_functions.php that intercepts Thesis page generation and directs it execute the new template. Add the following code to the end of places_template_functions.php before the lalst ?>
:
/* Get Thesis to invoke this template*/ if ( !is_admin() ) { add_action('thesis_hook_before_content_area', 'places_page_template_swap_before_content'); add_action('thesis_hook_after_content_area', 'places_page_template_swap_after_content'); } function places_page_template_swap_before_content(){ if (is_page()) { global $post; global $swapped_post; $page_template = get_post_meta($post->ID, '_wp_page_template', true); if($page_template == 'places_template.php'){ update_post_meta($post->ID, '_wp_page_template', 'custom_template.php'); $swap_id = time(); update_post_meta($post->ID, '_places_template_swapped', $swap_id); $swapped_post = $post; } else{ $template_swapped = get_post_meta($post->ID, '_places_template_swapped', true); if(!empty($template_swapped)){ $swapped_post = $post; } } } } function places_page_template_swap_after_content(){ if (is_page()) { global $swapped_post; if(isset($swapped_post) && is_object($swapped_post)){ $template_swapped = get_post_meta($swapped_post->ID, '_places_template_swapped', true); if(!empty($template_swapped)){ $page_template = get_post_meta($swapped_post->ID, '_wp_page_template', true); if($page_template == 'custom_template.php'){ update_post_meta($swapped_post->ID, '_wp_page_template', 'places_template.php'); } delete_post_meta($swapped_post->ID, '_places_template_swapped'); } unset($swapped_post); } } }
You are now able to create a page, assign it the Places Template and view it to see the Places Ads column. Putting in the actual ad content can be done in the WordPress Widgets screen (Appearance > Widgets) by placing a suitable widget onto the Places Ads sidebar.
6) Positioning the Places Ads column
Since you have taken over the task of laying out the page columns, you’ll find that Thesis does not position the new column automatically. You need to add CSS to handle this. In this case, adding the following code to custom.css does the trick:
/* Ad column */ div#places_page_content { width: 656px; float: left; } div#places_page_content div#content { width: 545px; float: right; } div#places_page_content div#sidebars { width: 95px; float: left; } /* @end */
Update:
Some people who have tried the code in this tutorial report that everything works ok, but the new column doesn’t show up. The most likely cause for this is that the hook that allows Thesis to see your template is not getting called. The hook to apply is dependent on the framework (Thesis Options > Design Options > Framework Options) that you’re using for the site:
1. If you’re using the ‘Full-width framework’ then the hook used in the tutorial is the correct one: thesis_hook_before_content_area
2. For ‘Page framework’, the correct hook is thesis_hook_before_content_box
so edit the code in places_template_functions.php to replace:
– thesis_hook_before_content_area
with thesis_hook_before_content_box
– thesis_hook_after_content_area
with thesis_hook_after_content_box
Thesis 1.8 Note:
Thanks to Cannolo (in the comments) who allowed me access to his server, I was able to debug a peculiar problem that was afflicting some implementations of the Places custom template. It turns out that in Thesis 1.8, the call to the thesis_hook_before_content_box
hook was repositioned. The consequence of this is that the template swap performed by the hook now happens too late to be of any effect. The next available hook in the chain is thesis_hook_before_html
. Therefore, for those who chose to use the ‘Page framework’, apply the following modification to your code:
Edit the code in places_template_functions.php to replace:
– thesis_hook_before_content_area
with thesis_hook_before_html
– thesis_hook_after_content_area
with thesis_hook_after_html
Does this work in Thesis 1.7? Is it still necessary? Seems like a lot of work.
Thanks for contributing this.
Hi Pierre,
It IS a lot of work compared to the usual way in which page customization is done in Thesis. It’s meant to handle cases where you want a group of pages to use a different page structure from the rest of the site. The custom_functions.php route works if 1) you know the names/ids of the pages before hand and 2) you don’t mind hard-coding a large number of page ids if the pages you’re working with are more than just a handful. This method saves you having to know what pages are using the template.
The technique still works with Thesis 1.7
Thanks!
I loathe hard coding page information. I loathe even using conditional statements! These sorts of layouts really lend themselves to a functional approach, and it’s just painful to dig through various files where the same conditions are checked over and over again. I’m talking to you, ‘invert’.
Anyways, this is a good technique, and it adds to my arsenal.
Hi David,
You’re so right about ‘invert’! Hard coding is prevalent in the world of WordPress customization. People get away with it since there’s normally not much of a penalty. However, as you’ve said, it’s something I try to avoid whenever I can.
Thanks for appreciating 🙂
PS: What technique are you using with the Thesis functions?
A couple of years ago, I built myself a framework for really fast templating with Thesis. What I do is isolate tease apart the Thesis logic, and create functions which handle arranging the hooks directly. In some sense, it’s a longer way around the block. In another sense, assembling a new template is like snapping legos together, no conditionals at all. Sidebars and css can be passed in, a little more work gets custom headers as well. Ping me any time.
Hey David,
Nice to hear from you again! Interesting that you chose now to send me this when I was thinking that plugin and framework creators typically skip the part about making their products extensible and interoperable (I think it’s a word) with random code out in the wild. For example, the BuddyPress Extended Profile Fields framework has no easy way to add new field types. I’m in the middle of hacking together a solution to add an image field type while ensuring I do not edit core files. Doing this kind of stuff should be exactly like you phrased it – Snapping legos together 🙂
Thanks Alex.
I’ve found that having test harness in place allows much faster refactoring for API development. Without a test harness, it’s white-knuckle all the way.
Forgot to set the “Notify me” option.
I’m a bit confused by the last part. Why do you have to “swap” the template before and after the content hooks? Why not just override the template with the first hook?
Can you explain that a little bit more so I can understand what’s going on? Thanks!
Hi Chuck,
The template name swap is necessary because of the way Thesis works. When Thesis is generating a page, it checks the template name assigned to the page. It knows about the two in-built templates: no_sidebars.php and custom_template.php. If the template name does not match these then it is assumed that the page is using the Default Template and therefore any hooks you may have set up are not called.
Since the custom template file that we’ve set up is going to be ignored by Thesis, we have to change the stored template name to one that Thesis knows (custom_template.php) so the custom code can be executed. The line
update_post_meta($post->ID, '_wp_page_template', 'custom_template.php');
does this. Once the template has been processed, we need to change the stored name back to the original so that the page author sees it selected on the Template drop down list. The lineupdate_post_meta($swapped_post->ID, '_wp_page_template', 'places_template.php');
handles that.Hope this helps 🙂
Thanks. That does help explain alot.
Thank you very much for writing this code. I am having a few problems implementing it though. When I pasted the it in I get this error message:
Warning: Cannot modify header information – headers already sent by (output started at *****/thesis_17/custom/places_template_functions.php:2) in *****/wp-includes/pluggable.php on line 868
I would greatly appreciate any advise.
Hi Seth, great to know that you found the code useful 🙂 From your description, it sounds like the error has been caused by some space before the opening
<?php
directive in the source file. Make sure that nothing precedes the<?php
directive.Thanks, getting rid of the space fixed it. I got the sidebar showing on the page 🙂 but there two copies of the page contents. Do you have any ideas what might be happening?
Great! Now this other one is harder to determine without some more detail. Do you have a screenshot or link to the page?
Sure. Thanks for your help.
Sorry, I guess html is not accepted. Here is the url to a screenshot.
In case some else encounters the same issue, removing the line
thesis_content_column();
sorted it out.Hi,
Great post.I am spending more than 15 hours to getting a little spark to solve this same issue.At last I am near you.Thank you so much.
I think all configurations are completed.Unfortunately due to my limited knowledge which is not displaying our(places_ad_column) side bar.Which showing all other sidebar(sidebar1 and 2).What may be the problem.
Can you please give me any idea? Thanks!
Hi Ajith, if you list the steps you’ve gone through in getting the template to work, I’ll be in a better position to spot what’s amiss. Thanks!
Kalengi,
This is an excellent tutorial! I was wondering what effects will this have on upgrading to the next Thesis version? Aren’t you editing core files in the above example?
Luke
Hi Luke,
Actually one of the key things I was aiming at was to avoid touching any Thesis core files so as to ease upgrades. Once you have followed the steps and put the template in place, you’ll have all the code in files that Thesis does not touch during upgrades.
Thanks!
Hey great tutorial, really helpful. The thing I’m trying to do is almost exactly what you have done here with this (even down to a template for places). The only thing that’s different is that I’d like to be able to have the places template keep one sidebar on the right hand side so that I could just put my ads in with a widget instead (seems easier to me).
This may be above and beyond here, but how might I do this template while preserving a right-hand sidebar?
-JC
Thanks JC 🙂 I’m not sure the situation you’re describing requires this level of customization. If you want the ads to appear on the right sidebar on all pages, then it’s much easier to place the ad widget onto a standard Thesis sidebar. Thesis displays it’s standard sidebars on the right by default.
Well I’d like to develop a fairly sophisticated template in the end, but I want to build it on the basic platform of having one main content area with just one right-hand sidebar. Currently Thesis doesn’t offer “one sidebar” templates that I’m aware of, just the default and “no sidebar” options.
I guess I’ll probably be best served by creating a custom “one sidebar” template and then building what I need on top of that.
Oh, I see what you’re after. You can do that in Thesis by going to Thesis Options > Design Options > Site Layout. There you can select the 2-column layout under ‘Columns’ and then specify Content, Sidebar 1 arrangement under ‘Column Order’. That would give you a main content area with one right-hand sidebar throughout the site.
Is that what you’re describing?
Sort of. I don’t want one sort of template site-wide though, rather the option of selecting a one-sidebar, default two sidebar, or no sidebar layout for each specific page. For the main blog page, for example, I want the standard two-sidebar layout. But I’ll also have some pages that are more static in nature, where I’d really like to be able to do a custom layout based on a one-sidebar platform. I hope that makes some sense?
I’ll poke around a bit more about ideas with this, but if you can think of anything let me know. I’m sure I’m not the only one with this need!
In order to get just two columns on the custom template, you can leave out the line
in places_template_functions.php. The sidebar is placed on the right by default. The one in the example appears on the left due to some additional css.
Instead of “Great Work! Can you help me with…” 🙂 I’m just going to say
AWESOME!!
Thanks! 🙂
Kalengi,
Been trying to get custom pages to work in Thesis for months… and I was really excited about this tutorial because it looks like it should work, but alas, I cant get it to read the custom template. I think I did everything right. The functions file goes in thesis/custom. Template file goes in the main thesis folder. I copied and uploaded custom_functions.php and custom.css to their right place. The template is showing in the dropdown on the page and the new sidebar widgets are showing in admin. For some reason, its not reading the template. http://drlab.digitalrenewal.com/thesis
Seems like everyone else is getting it wroking… Any Idea what I might be doing wrong? Has anything changed in the last month in thesis? I have version 1.7
Thanks so much!
Trisha
Hi Trisha,
Looking at the link that you posted, it seems the custom page handling is not being triggered. The page displayed is using the Default Template selection. Edit the Places page (id=4), select Places Template on the Template drop-down and then click on Update to save. With this done, the template should be called when the Places page is loaded.
Thanks for appreciating the tutorial 🙂
Thats why I was so confused… the Places template IS selected from the drop-down.
It’s a great tutorial! Very well explained, and of all the ones I’ve tried, this seems like the best way to do it.
Send me your code on mail. I’m sure the answer’s in there somewhere.
Very helpful post. I just created a new template and it is working fine, but I am getting some problem, I don’t want any default sidebar in my new template. how can I fix this problem. It will be great help.
Hello Anjani,
The default sidebars can be omitted by removing the code
thesis_content_column();
from places_template_functions.phpThanks 🙂
oops! @Anjani I accidentally copied the wrong line of code. The line that controls the default side-bars is
thesis_sidebars();
. That’s the one you should remove. Sorry about the mix-up.This is so great! Thanks a million!
You’re most welcome @kate 🙂
Hey Kalengi,
thanks for sharing your knowledge.
When creating a page I’d like the ability to designate it as either:
a. 3 column 2 sidebar on the right.
b. 2 column 1 sidebar on the right.
c. 1 column no sidebar.
From what I gather this means I would have to create 3 different custom templates using your method. Chances of me doing this without blacking out the eastern seaboard are currently 0%.
If you would be interested in talking/typing me through the process I would be interested in paying you to do so.
Let me know.
Hi waaahoo! Sure thing, I’ll get in touch on mail.
Thanks 🙂
Thanks for your reply!!!
I removed the thesis_sidebars(); from places_template_functions.php.But it is showing those side bars.Don’t know how can i get rid of this.Please help me on this.
🙂
Anjani
@Anjani: Sounds like there’s some other custom code in custom_functions.php that is activating sidebars on pages.
Hi kalengi 🙂
Really appreciate your quick response.Thanks a lot Sir!!!!
So what should i do now to remove sidebar from this page….
Please help me!!!!
Thanks
Anjani
Sure @Anjani, let’s have a look at your custom code. I’ll get in touch on mail.
Thanks for your quick response!!!
yes there is some custom code and widgets which has been used here.So how can i remove these at this template.I don’t want these at my new template like no_sidebars
@Anjani – I sent you mail on your registered address.
Thanks for sharing this, it is just what I have been looking for. I can’t get it to work though. I would be very grateful for some help. In wp-admin everything seems okay. I have the template in the drop down list and have applied it to a page called France. The places sidebar shows up on the widgets page, and I’ve put some widgets on it. On my France page, the column doesn’t show up, and I can’t see the reference to the places_template.php in the pages source code. I’m using thesis 1.7.
Hi Carmel,
I’ll do a quick check on Thesis 1.7 and then get back to you.
Thanks for appreciating 🙂
might it be because the themes folder is thesis_17? This might mean that codes for other versions wouldn’t not work here if this folder name is in the code.
@Carmel: I’ve confirmed that Thesis 1.7 is not the cause. I think the most likely mis-step is naming the custom template file something other than places_template_functions.php . It’s important that the file name matches exactly.
these file names are right.
The page I have tried to modify is http://carmeljames.com/myblog/?page_id=100
Hey Carmel,
I think Thesis is the culprit after all 🙂 Since Thesis started appending the theme version to the folder name, it’s tempting to upgrade by copying the thesis_17 folder into the /wp-content/themes folder while the previous thesis folder (perhaps thesis_16) is still in place. The end result is a corrupted upgrade.
You may not notice any problems until the moment you decide to create a custom template. Everything about the Places Template is OK, but WordPress cannot find it since Thesis 1.7 is not registered properly. One way to sort this out is:
1) Make sure you have only one copy of Thesis (thesis_17 in your case) in the themes folder by deleting any other copies apart from the one you’re using.
2) Visit Appearance > Themes page to activate Thesis. It is likely that you’ll find no selected theme.
That should sort out the problem. Let me know how it goes.
Thanks…
I didn’t upgrade, I jumped right in at version 1.7.
I definitely have thesis running, been using other features.
Here’s another likely cause. If you’re using the ‘Page framework’ layout of Thesis, then the action hook to trigger the template code does not work. In order for the template to work, select ‘Full-width framework’ on the ‘Thesis Options’ > ‘Design Options’ > ‘Framework Options’ section. For a thorough explanation of the difference between ‘Page framework’ and ‘Full-width framework’, see this video turorial by Kristarella.
If you want to keep the ‘Page framework’ setting, then make the following changes to the template code in places_template_functions.php:
1) Replace
thesis_hook_before_content_area
withthesis_hook_before_content_box
2) Replace
thesis_hook_after_content_area
withthesis_hook_after_content_box
sadly, I’m am already using the full-width framework.
I really appreciate you spending time thinking about this.
I can’t help feeling I’ve done something wrong, but I checked it yet again today, and I can’t find any mistakes.
I am however very limited by the “Fatal error: Allowed memory size … ” that seems to be very common. I’ve tried everything but I can’t even upload pictures now without that error popping up. I’m waiting to hear from the people hosting my site. If I can fix that, maybe this will work, though it’s hard to imagine memory is preventing it from happening.
I will look at other options that I’ve changed and see what happens.
Hi,
Really appreciate the tutorial as it provided an easier solution than the one I was originally trying.
The only problem I have are the default sidebars are showing, which I don’t want. I’ve removed the line ‘thesis_sidebars();’ from the template file and cleared out my custom_functions.php file apart from the entries to load the template into Thesis but they still show up.
Any suggestions as to where else I should look? I’m using Thesis 1.7 (new install).
Thanks
Hi Byron,
Is the custom sidebar showing? What is the url to the page having the custom sidebar?
Thanks…
First, thanks so much for such a great tutorial. I’m nearly there.
I’m using 1.7 (no previous versions) and following the directions, it still wasn’t pulling up the new template.
I did some troubleshooting and found that unless I pick “custom template”, the add_action(‘thesis_hook_custom_template’, ‘places_page_layout’); doesn’t fire.
If I switch the template to custom (in the WP template drop down), then it fires.
So what am I missing? I copied the custom_template.php and renamed it, then changed the template name in the comments. Otherwise it’s the same.
Thanks for any additional help.
Hi Wendy,
Sounds like you may be facing the problem I described to @Carmel in this comment. See if it sorts out your issue.
Hope you get there 🙂
No – I saw that and did that. And it did fix a problem. After that was when it started working if I selected the custom template. It just won’t fire the “thesis_hook_custom_template” if I don’t pick custom template in the drop down. Which seems very weird to me because both template files have the same line of code in them, shouldn’t they do the same thing?
I think my mental model of your setup is broken 🙂 I require some more detail so I can have better context and perhaps spot the problem.
That’s pretty slick. I’m doing it slightly differently, using the Thesis functions as built-in “bricks” to set up a variety of page types. It was easier in 1.6. The control of flow in 1.8 seems more difficult to get a grip. If I didn’t want arbitrary sidebars, it would be pretty easy though.
Try —
remove_action(‘thesis_hook_custom_template’, ‘thesis_custom_template_sample’);
add_action(‘thesis_hook_custom_template’, ‘places_page_layout’);
You must ‘remove’ it first then add it 😉
Cheers,
asoel
Hi asoel,
Thanks for pointing that out! I’ve updated the code.
customizing a customize theme..hmm is there anything yet complicated than this?
There’s no end to customizing 🙂
Pls kalengi help me i don’t know how to add your function in Thesis.
Thanks
Hi Owen,
Please describe the steps you’ve taken so far so I can see how to help.
Thanks…
what is step1 to do and next step to do
thanks
for example
step 01 is create “places_template_functions.php” /wp-content/themes/thesis/custom
Hi Kalengi,
how to create “Register the new custom template in WordPress”
thanks so much
thanks kalengi right now is working on my own wordpress website.
this page
places_template_functions.php.
doesnt seem to exist in thesis 1.8, so how do I proceed?
what Im trying to do is make my post pages sidebar 1 free…so this gets me a pice of the way there….
help
thanks
larry
Hey Larry,
The file places_template_functions.php doesn’t belong to Thesis. You create it as described in step 2) in the same location as custom_functions.php
Hope this helps! 🙂
Hi Kalengi,
Thanks for the great introduction to Thesis and its hooks. You have provided the easiest to understand version, by far 😀
I’m running on Thesis 1.8 and I styled my “About” page using the “no sidebars” attribute. I left it there for a while to do some work and recently returned to revert back to the regular template only to find that the “template” feature is now missing!
Does your code function to retrieve missing features like this? Will really appreciate your help here.
Hi Christine!
Thanks for your appreciation 🙂
Do you mean that the ‘Templates’ drop-down is missing from the page editing screen?
Hi Kalengi – Yes, the “template” feature is missing. The only features I have are “Parent” (also missing the drop-down menu) and “Order”. It’s really weird as I don’t experience this with my other blogs. Thanks for responding.
The ‘Template’ drop-down disappears if your theme has no templates to select from. Since you’re using Thesis, there’s always at least two templates: Custom Template and No Sidebars. The only reason I can think of that these templates aren’t listing is there’s another version of Thesis present in the themes folder. For example, if you still have Thesis 1.7 (thesis_17) folder in your themes folder, it could interfere with the loading of the Template list. In this case the solution is to remove the older Thesis folder and leave just the version you’re currently using.
Hope that helps!
Hey, just wanted to comment to confirm this still works with thesis 1.8 also as I have just implemented it. Thanks for this approach Alex, its so much more user friendly. I have used this and instead of pulling a custom sidebar in, I am calling custom meta content for a 1 sidebar template and 2 sidebar template using multiple wysiwyg;s on the edit page screen. I am using wpalchemy which you can see here…
http://farinspace.com/multiple-wordpress-wysiwyg-visual-editors/
http://farinspace.com/wpalchemy-metabox/
Might be useful to someone else.
Thanks very much David! It’s definitely helpful to confirm compatibility with Thesis 1.8 and even better to know that this tutorial has helped you 🙂
your tutorial is awesome….execept: as you can see if you to my page, i am getting that block of code at the top and i’m not sure why. any ideas would be great. thanks.
Hi Niki,
Thanks for the appreciation 🙂 What code are you referring to?
oh shoot…i removed everything because it was driving me nuts….
its this chunk:
/* Get Thesis to invoke this template*/
02
if ( !is_admin() ) {
03
add_action('thesis_hook_before_content_area', 'places_page_template_swap_before_content');
04
add_action('thesis_hook_after_content_area', 'places_page_template_swap_after_content');
05
}
06
07
function places_page_template_swap_before_content(){
08
if (is_page()) {
09
global $post;
10
global $swapped_post;
11
12
$page_template = get_post_meta($post->ID, '_wp_page_template', true);
13
if($page_template == 'places_template.php'){
14
update_post_meta($post->ID, '_wp_page_template', 'custom_template.php');
15
$swap_id = time();
16
update_post_meta($post->ID, '_places_template_swapped', $swap_id);
17
$swapped_post = $post;
18
19
}
20
else{
21
$template_swapped = get_post_meta($post->ID, '_places_template_swapped', true);
22
if(!empty($template_swapped)){
23
$swapped_post = $post;
24
that appeared at the top of my page….also at the top of my admin dashboard.
I see… Would you mind putting it back in so I can see how it looks?
hmm….put it all back and now seems to be working just fine. thank you very. one question…if I want to edit the template, say with the same red heading text on each page that uses that template…where would i make that change?
Great! Then that issue’s sorted.
The per-page heading would go just before the line
<div id="places_page_content">
This would place it above the page content.Ok…in which file?
That’s in the file places_template_functions.php
ahh i feel so stupid…body {color: black;}
h1 {color: red;}
put that in but nothing changed
What page are you expecting to see the change on?
on the “about” page
the “hi” text
This is somewhat off-topic, but the custom formating in Thesis should go in custom.css as indicated in the tutorial.
Hi, I removed the because I don’t want the sidebars to appear, but they still do. Any other suggestions?
Hi Niki 🙂 You removed what, custom.css?
I removed the from the file but am stilling get normal side bars on the page, which I dont want. Any suggestions?
it keeps taking the code out of my response. i removed the side bar div out of the functions file but they sill show up
@Niki If there’s some way I can have a look at the file then let me know through the form on the blog’s sidebar…
I’ve done everything to the letter, and the default sidebar still shows up. Everything else works: the template shows up in the drop-down, the page publishes with the dummy text I’ve entered — just no custom sidebars. (I’m using v1.8.) (By the way, thanks for the clear instructions. Clearest I’ve seen.)
Hi Cannolo,
Two things come to mind that may sort you out:
1. If you don’t want the default sidebars showing up, then remove the code
<?php thesis_sidebars(); ?>
from places_template_functions.php2. Read the section titled Update: at the bottom of the tutorial. It may explain why the custom sidebar is not showing.
Thanks!
Kalengi, thanks for your reply. That “thesis_sidebars” code was in there, and I took it out. I also checked the update, which I had taken care of before. It still doesn’t work. I’ve double-checked everything. What else could it be?
I also tried this on a test site running These 1.8, with and without plugins activated. Same result: template shows up on the edit-page page, and the “Places” widget menu shows up in Widgets. There’s just no Places sidebar.
OK, if you page is at a location I can access, then I could have a look. Please message me the link using the form on the blog’s sidebar.
Sent. Thanks.
@Cannolo I got your message and tried accessing, but there were access restrictions. I’m not sure whether you’ve received my response on mail 🙂
Hi,
I’m new to Thesis but I cant get Thesis to do what I’m wanting for my real estate web site. Most of my pages will be 3 column content in middle with a sidebar of menus on either side. Questions are (1)Is it possible to have custom page that contains only one side bar on the right that shows different menu items to sidebar 1 & 2 on the other pages.{A 3rd men} and(2) Is it possible to modify the side bar padding/text size of the sidebar menus without it effecting the main nav? (They take the main nav bar foremat, which doesn’t look right on the sidebars, looses to much space between menu items)
Hi Steve,
Yes, it’s possible to create a 2-column custom page and it’s also possible to format the sidebar menus independent of the main nav. You can use the contact form in the blog’s sidebar to describe in more detail what result you’re looking for and then we can go from there…
Thanks 🙂
Wow. This is an amazing tutorial. Would love to contribute a donation to you.
Hi Perry,
What an awesome thing to do! Sure, just write me via the contact form in the sidebar and we can go from there 🙂
Thanks!
For anyone out there who is having difficulty with Thesis or need some special customization, I would recommend you dont waste any time and just contact Alex as I did. Not only does he answer questions asked on his blog (Which I found many many dont do) but he is willing to help with special custom work as he did for me when I needed something extra tricky on my site. He listened, made sure he know what I wanted and then delivered exactly as he said he would within a week. It works perfectly, great job Alex and thank you!!!!!
Thanks very much Steve for this wonderful comment! It was truly a pleasure setting up the custom template 🙂
Hey Alex,
Did you get my email about the custom template problem I found the week later where it has reduced in page width, compared to the pages before the custom change?
Still shows the same pix wide in view source but it is smaller. Check the search pages, which is still using the wrapper from before the change and then check the width of any other page not part of the search sub domain and you will see they have reduced in size. Can you correct it please?
Hi Steve,
I got the message and responded a few days ago, so I’ve been awaiting your response. I’ve just re-sent it so let me know whether you’ve received.
Thank You 😀
You’re welcome 🙂
Hi Kalengi, thanks for post. I have a question. I’m doing it step-by-step, but after 3rd step, my template doesn’t listed in template’s dropdown? why? please help me)
Hi Karlen,
The first cause I can think of is that the file is located in the wrong folder. Confirm that the places_template.php is located in Thesis template folder.
Having some trouble… I am able to see the Places Template when creating a new page, but it shows an asterisk like: Places Template *
I am not advanced enough to know what is wrong. And when I go to view the page nothing seems to have changed.
I Greatly Appreciate your help!
Hi @RootedUp,
I think the asterisk is coming from the commenting in the header of places_template.php . Copy the code again exactly as it is in step 3 (Create the template placeholder file).
Thank you! Well the asterisk is gone, but I still can’t view the page in the new template…
It’s tough to figure out what the problem could be with out more details. You can use the contact form on the sidebar to send me your site’s login details so I can have a look, if you don’t mind.
I am getting the widget to show a text box on the left, but I still have theme content showing on the page…
http://fakenewdomain.rootedup.com/advertise/
We can have a look at this right now if you’re available.
Hi, thanks for all your help, I still am experiencing a small problem when I try to replicate this to create a second page from these instructions. Please see http://polibama.com/subscribe/ … the content of the homepage is showing up below the custom content for the “Subscribe” page.
I can’t get this to work for the life of me. I am not new to PHP, wordpress, nor templating. I really wanted to start using hooks but I am about to give up.
Why can’t I just add a custom_template_name.php, enter my hooks, and be done with it?
This is insane. I am trying to create a custom page.
So instead of this, I tried to just use the if_catagory() to call a page catagory using the custom taxonomy plugin but thesis is ignoring that for some reason also. Does anyone know of a basic, single page layout custom template with how to add it?
Hi @badjesus,
Yeah, Thesis takes some getting used to 🙂 The reason it doesn’t work with file-based templating is that all the templates are defined in code using the hook system. You just need to learn the right hooks to call for the page structure you desire. If all you want is a single-column page layout, then pick the “No Sidebars” template option when creating a page.
How would I use this process to create multiple page templates? If you have to select “custom page” when you are choosing which template to use, how would that work with multiple templates?
also, is there a way to create a left and right sidebar for each template?
thanks!
Hello @nikers85,
The code as it is assumes that you’ll be using only one customized template. In order to have two or more, you’d have to change the code to detect which particular template was selected for the page and then run the code for that template. Such info could be placed in a global variable before swapping out the template name. I’d need to look into that scenario a lot closer in order to know what sort of information has to be kept around, but generally that’s the approach I’d use. Oh, and you need a separate template file for each template you create so WordPress can pick it up and list it.
Now about the columns… Thesis already has the sidebars inbuilt. Unless you’d like different columns on different templates to perform functions that are not uniform across the site, I see no reason why you cannot use the sidebars that Thesis provides. To call up the Thesis sidebars, use the code
thesis_sidebars();
.To create additional non-Thesis sidebars, use the code in the function
places_ad_column()
together with theregister_sidebar()
function and remember to replace ‘Places Ads’ with the name of your new sidebar.WordPress will automatically load a variety of templates, if they are available to the theme. Breaking out all the Thesis layout functions lets one mix-and-match in arbitrary templates. Easier, more flexible and portable then attempting to manage page rendering by globals and $post->ID. Disclaimer: I sell a very expensive product which does this.
I could do just the sidebar part without the page templates. I really just need to replace sidebar 1 and sidebar 2 on specific pages with new sidebars, any suggestions on how to make that happen?
You could probably do what you want with a simple hack of the Genesis Simple Sidebars plugin.
This plugin does the trick! Similar to the Genesis Simple Sidebar plugin.
http://wordpress.org/extend/plugins/custom-sidebars/faq/
Thanks for all the help!
It still works great in Thesis 1.82. Now, does anyone know how to substitute in a unique header for the page? Help!
Hi Susan,
In order to modify the page header, you need to utilise the header hooks. The steps involved are:
1. In places_template_functions.php look for
add_action('thesis_hook_after_content_area', 'places_page_template_swap_after_content');
Below that insert the code:
2. Add the following functions to the same file:
That should do it! Modify the function
places_page_header()
to display whatever unique header you want on the places pages.I was thinking one way to do it is use a conditional tag with a header function. But the is_page_template tag isn’t working.
What’s the easiest way to adjust the site width just for specific pages? My first stab was to make a new custom template page, call the thesis_html_framework, then immediately modify the container parameters via jquery .css() calls using a hook after html. This works, but the site can sometimes render with the normal width, then snap wider. I’d like to somehow prevent the current css from loading (set in the thesis backend gui) and have specific css for these pages that I specify using a template page. Do I clone and hack up the thesis_html_framework function?
Hi Sean,
The first idea that comes to mind is changing the page class and letting the css adjust accordingly. The
body_clas
filter is perfect for this kind of task.Yup, that’s perfect. Thanks!
I am a professor of physics and I have recently installed Thesis 2.1.4 on my blog http://yashplus.com
I want to display my home page just like Pinterest.com board. i.e. small rectangular pages with little excerpt and when somebody clicks one of them, he will be redirected to that page. I want this on my home page i.e. without widgets. Can I do that? Please guide. I have been searching it since long. But nobody helps. I read the highlighted comment on your site and thought that you might be a source of light to me in dark.
Please help
Hello yashplus,
I’d be glad to help. Send me a message through the contact form and we can take it from there.