Provides a drop-down to select different templates for posts from the post edit screen. The templates are defined similarly to page templates, and will replace single.php for the specified post. This plugin will NOT switch the templates for the different posts in a listing page, e.g. a date or category archive, it will only affect the template used for single posts (i.e. you can choose a template which is not single.php).
Post templates, as far as this plugin is concerned, are configured similarly to page templates in that they have a particular style of PHP comment at the top of them. Each post template must contain the following, or similar, at the top:
<?php
/*
Template Name Posts: Snarfer
*/
?>
First note: Page templates use “Template Name:“, whereas post templates use “Template Name Posts:“.
Second note: You must have the custom post template files in your theme in the same directory/folder as your index.php template file, not in a sub-directory/sub-folder.
Download
Latest version: Download Custom Post Template v1.4 [zip]
Installation
The plugin is simple to install:
- Download the plugin, it will arrive as a zip file
- Unzip it
- Upload
custom-post-templatedirectory to your WordPress Plugin directory - Go to the plugin management page and enable the plugin
- Upload your post template files (see the Description for details on configuring these), and choose them through the new menu
- Give yourself a pat on the back
FAQ
Q. I get an error like this: `Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or ‘}’ in /web/wp-content/plugins/custom-post-template/custom-post-templates.php`
A. This is because your server is running PHP4. Please see “Other Notes > PHP4″ for more information.
Changelog
v1.4 2011/08/14
- Added a filter,
cpt_post_types, so people can choose which post types this plugin shows the UI for - Linked to WP.org, not my site, for documentation (quicker to load)
v1.3 2010/06/17
- ENHANCEMENT: Now works with child themes, hat-tip Kathy
- LOCALISATION: Now ready for localisation!
v1.2 2010/04/28
- ENHANCEMENT: Now sporting a conditional
is_post_templatefunction/template tag which is functionally equivalent to the core WordPress is_page_template conditional function/template tag - ENHANCEMENT: If the theme uses the core WordPress (body_class)[http://codex.wordpress.org/Template_Tags/body_class] template tag, then you will have two new classes added: “post-template” and “post-template-my-post-template-php” (where your post template file is named “my-post-template.php”).
v1.1 2010/01/27
- IDIOTFIX: Managed to revert to an old version somehow, this version should fix that.
v1 2010/01/15 (released 2010/01/26)
- BUGFIX: Theme templates now come with a complete filepath, so no need to add WP_CONTENT_DIR constant to the beginning.
- ENHANCEMENT: Metabox now shows up on the side, under the publish box… where you’d expect.
- Plugin initially produced on behalf of Words & Pictures.
v0.9b 2008/11/26
- Plugin first released
v0.91b 2008/11/28
- BUGFIX: The plugin was breaking posts using the “default” template, this is now fixed. Apologies for the inconvenience.
- Tested up to WordPress 2.7-beta3-9922* Tested up to WordPress 2.7-beta3-9922
v0.92b 2008/12/04
- Minor code tweaks
- Blocked direct access to templates
When I go to Add New Post, I get an error message on the right sidebar.
The error is:
Warning: file(/themes/zenko/legacy.comments.php) [function.file]: failed to open stream: No such file or directory in /nfs/c05/h02/mnt/74166/domains/sacasiancc.org/html/wp-content/plugins/custom-post-template-1/custom-post-templates.php on line 125It shows this error for all the files in the theme folder.
@Darren – I think I’ve fixed this issue, please would you try the latest Development Version and let me know if it solves your issue? If it does then I’ll make a new release of the plugin.
Thanks for the plugin! I REALLY needed it, it should be built-in!
So far I use 4 templates, everything went very smoothly, so this email is just a big thank you.
By the way I mentioned you in my credits: http://www.marinepacault.com/credits
Thanks again,
Marine.
I feared to update WordPress until you released v1.2. Now it works perfectly and the new ‘is_post_template’ allowed me to load different scripts in a fifth post_template.
I am so happy with the plugin that I don’t feel like digging in WP3′s new functionalities – I think I saw something similar to built-in posts templates, but I was not convinced at first glance.
Thanks again,
Marine.
Just wanted to say that this is a great plugin.
Is there any chance this could be made to work with
either Custom Post Type UI (http://wordpress.org/extend/plugins/custom-post-type-ui/) or GD Custom Posts and Taxonomies (http://wordpress.org/extend/plugins/gd-taxonomies-tools/) plugins? It would be incredible to have custom themes depending on the post type.
Hi. What is the model for the template file? single.php? Also, does this plug-in work with custom post types? I have configured a custom post type in WordPress 3.0 but post templates do not show as an option when creating/editing items for that custom post type. It would be great to be able to create different templates for the custom post types.
If you are using only your custom post type and not the standard post type, then a quick fix is to change ‘post’ in line 48 of custom-post-templates.php (the add_meta_box line) to the name of your post type.
My configuration doesn’t need to use the standard post types, and I only want custom post templates for my custom post type. I don’t know enough php to make it show up on both at once, but I’m sure it can be done.
Actually you just copy line 48 and change ‘post’ into the name of your custom post type. You can have as many copies of the line after another, each with the name of your custom posttype instead of ‘post’.
A nicer way would be to just add all posttypes in a loop if you want this function on all post types. I just don’t know how..
HA, just refound my own comment because i made a spelling mistake and didn’t quite understand why the dropdown stopped working in one of my post-types
Thanks again for a greate plugin!
I have the same issue with WP3 – the metabox for selecting the post type does not appear. Is there an alternative way around this?
Hi,
Activated this custom post template plugin but i cant select the template i created in the specified manner. server is running on php5. kindly lmme know if there is a solution.
Hi Anoop, can you please check the “development version” here: http://wordpress.org/extend/plugins/custom-post-template/download/
Sent you email, sorry didnt relize you have a blog/comment section. I’ll repeat for the benefit of others who may have the same issue
I wonder if there is a way to set that a particular category should always use a selected post template without having to select it every time. The reason I ask is because I have a lot of older posts in a particular category which I would like to move to a news single post template going through all the old ones and changing them would be a pain. If I could just set a default would make it much easier
Thanks for a great plugin exactly what I need
You have a possible bug in v 1.3 that is currently out. The problem for me was it wasn’t detecting any template files even though they were there.
I checked in to the code and it was a problem with paths… The array of template files generated in the function CustomPostTemplates::get_post_templates() was receiving a list of relative path names (eg “/themes/mytheme/file.php”) rather than a list of absolute path names for each theme file.
This was throwing off your other code that tried to strip the theme path and also caused problems when trying to open files (though it never got there, thinking all files were in sub directories and ignoring them).
The fix is…
Right above where you set $base, add this:
$root = dirname(get_theme_root());
Then, right above where you set $basename, add this:
$template = $root . $template;
This corrects the path name of the template files allowing the rest of your code to work properly.
Thanks Eli! Oddly that doesn’t seem to happen for me, so I’ve added in some conditional code to try and detect when it needs to happen… can you please check the development version here: http://wordpress.org/extend/plugins/custom-post-template/download/ please?
Hi, in wp3 what is the file that i have to use like example for to start with new post template?
Thanks.
You would probably start with whatever template your theme had for single posts, perhaps single.php or even index.php, add the code to the top as described above in the instructions, and work from there.
Many thanks for creating this plugin.
I have been looking for this plugins and finally I foud this!!
*AWESOME PLUGINS*
Yes, this is a great plugin. Thank you!
I have tried to used for customizing category pages by placing the php snippet on top of a single.php and calling it Template Name Category: Snarfer, or Template Category: Snarfer, but this obviously did not work.
Is there a way to tweak this fabulous plugin to make it work for category pages also?
I was in the middle of asking why this didn’t work, when I realised that I may have done something wrong.
These plugins really do need a simpletons guide for people like me
I put the new template in the plugins directory, when it should have gone into the themes directory.
eg:
Wrong way: /wp-content/plugins/custom-post-template/newtemplate.php
Right way: /wp-content/themes/rt_afterburner_wp/newtemplate.php
Now to work out how to change the template, and see if it can do what I hope it can.
I want to remove the left column, and maybe even remove the top widget space ?
I’ll come back in a week or so, and ask again, if I can’t work it out.
Playing with these codes is interesting and frustrating at the same time. Thank goodness I am retired, and have the time
Absolutely perfect. Thank you!
With the method described here http://wordpress.org/support/topic/plugin-custom-post-template-no-dropdown-in-page-editor
the drop down menu is available again for post edition in the administration, It disappeared without reason since WP 3.0
Great Plugin,is the there a way to have the templates in a folder in the theme directory..
gracias !!
Dear Simon,
Great plugin! Thanks for your work.
I have one feature request:
It would be great if this plugin also would work for cutom post types! I have some custom post types where i like to select a different template.
What do you think?
Regards,
Rein
This plugin looks like it will be valuable for an effort underway but I wanted to tested it on Xammp before adding another plugin to my business website.
The plugin activated without error on WP 3.0.2. I’ve added my custom script to the theme directory.
When I open up “edit/add post” in wordpress, I’m informed that my theme has no custom post template. It does, and it is installed in the them folder.
I suppose I can try it in a development site on my hosting account but the only stipulated requirements are WP 3+ and PHP 5+. Xammp is using PHP 5.1.x and the installation of wordpress on localhost is 3.0.2.
What am I missing?
With my new posts it selects a category which then it adds to my menu “techs” then if I click the “techs” menu item it goes to the page which is blank but when I click “continue reading” it goes to my php template?
I want to just have it go to the template. Is there any way to remove that step where it goes to the “continue reading” page?
Your help is appreciated.
Thanks
Mitch
THANK YOU, THIS PLUGIN IS AWESOME!
Just what I was looking for. I am in architecture, not web-code, and this has been so helpful for a site we’re creating. Thank you!
Hello,
What might be the tweak for the plugin if I want to use it not for a single post? but a category of posts?
Thanks in advance.
Charels
Unfortunately that is a situation that this plugin is not currently set up to deal with.
Regards,
Simon
Fatal error: Cannot redeclare class CustomPostTemplates in /home/content/10/7387510/html/wp-content/plugins/custom-post-template/custom-post-templates.php on line 175
That’s the error i get on the dashboard when I try to activate the plugin. What should I do?
Thank you
That sounds as if WordPress is somehow loading the plugin twice, weird! Do you already have the plugin installed? Does it come bundled with your theme? You might try renaming the plugin folder, visiting the plugin page in admin (this will disable the plugin), then naming the plugin folder back to it’s original name and re-activating it. (If this works then you might have had two versions of the plugin installed and/or activated.)
If that doesn’t work, try changing the theme to TwentyTen and see if the problem still exists. (If the problem does still exist then the plugin is bundled with your theme, and you should talk to the theme author.)
Good luck!
Simon
Unfortunately bulk edit for posts doesn’t allow me to set a large number (in my case, all) posts to a custom template.
How can I set all existing posts to a custom template (leaving the default template to future posts)?
I’d be glad to do this either by exporting the .sql file or by a batch command in myPHPadmin.
For example, in a text editor looking at the .sql file, I can see:
\r\nmeta_key custom_post_template \r\nmeta_value post-notitle.php
which references my post-notitle.php file.
But I don’t know how to insert this into a MySQL table for all custom_post_template fields.
Currently I’m using the meta key ‘custom-post-template’, but in a future version I may switch to ‘_custom_post_template’, as meta keys (custom fields) prefixed with an underscore are consider hidden so it will be less interface clutter in the editing screen.
Cheers,
Simon
Thanks for the plugin!
Hi,
I think it is exactly what I need, and I installed the plugin on the latest version of WP.
I created a new file (copy from singlepost.php) and added a table to be shown on the template page, but the page stays blank, no table to see.
Should I add something special on the new template?
Hi,
I have edited line 48, replacing ‘post’ with my custom post name and the drop-down now shows up on the right and lets me choose from my 5 templates. When I save the post, it saves the preference but when I load the post in my browser it will not load my chosen template. Any ideas? This is a great plugin if I can get it to work. Thanks for your time! Appreciate your work.
ed.
I know this is a bit off topic but I have wasted my whole day searching the web for some more comprehensive threads on this topic. I did get several good facts from this website.
I installed the plugin and created a couple post themes in the themes root directory. I added the appropriate php to the top of my post themes and named them single-video.php and single-work.php – non of the themes appear in the dropdown when creating a post. All I see is “This theme has no available custom post templates.”
Brian,
I was running into the same issue, u have to change:
Template Name Posts to : Template Name Posts:
see below
Note that page templates use “Template Name:“, whereas post templates use “Template Name Posts:“.
Cool thanks that works not sure why the instructions don’t say that.
I have this same problem, but this solution doesn’t do anything for me. What I’ve done, just to test if it works, is put the code
at the top of a copy of the single.php file (named single-test.php), but when creating a new post I only see “This theme has no available custom post templates.” Any ideas what might be wrong?
Howdy,
I’m being really dim, can someone post the php to a single column layout I can use for posts please?
Thanks,
Matt
Hi Simon,
The plugin works like a charm. However, it does not work when using WP 3.1 and Custom Post Types. The Drop Down box simply doesn’t show on the edit screen of the Custom Post Type.
Any idea how to fix this maybe?
Thanks,
Martin
Okay, maybe I am an idiot but I do not see any instruction on where to upload my templates. Can someone please enlighten me. Thanks.
I don´t know how to use. I put the code in the top of file, but with wich name? I try to use “single-boletim.php” and put in the top “/*
Template Name Posts: single-boletim
*/” but any result. What do I have to do?
This is an awesome plugin – thanks so much! It works like a charm
Exactly what I was looking for. Hoping it’s as easy to convert my page template to post templates as you make it sound
Works like a charm. Much thanks.
Is this plugin compatible with “Suffusion” theme.
Does this work with WordPress 3.2-beta2. and the Twenty Eleven theme?
Hey man, great idea!
I installed the plugin, duplicated the single.php file and customized it as a template, as per your instructions. It appears ok in the Post Template Selector.
I then created a new post and assigned it to this new template, then saved it. Problem is, the font-end still displays the post with the default template instead of the one selected.
Any ideas?
Thank you,
Eros
I have a customer post template set up within a custom theme for a monthly newsletter, and the “What’s New” nav listing in the sidebar has dropped to the bottom of the page on the newsletter Landing Page (showing exceperts of all the artcles in the newsletter). This same What’s New nav listing is fine when you are reading any of the individual newsletters (it shows up in the sidebar at the top of the page). I’ve set the categories and custom fields for each article correctly.
Any idea where to find the source of the problem?
Thanks!!
Thanks, great plugin !
within my post, the plugin says that my theme has no custom post templates…no what?