Recently, a commenter asked me about creating single post templates in WordPress. This was actually something I’ve been working on as a side project for a while now.
The original code I started working with came from Nathan Rice’s post on creating post templates, but I wanted to expand on that idea a bit.
What is a single post template?
Well, they’re sort of like what we can do with page templates or category templates. You can use a specific post template for single posts that you want to function differently.
For example, in this tutorial, I will tell you how to create single templates based on post ID, category, tag, and/or author. You could potentially make all posts by author Jane Doe behave in a different way than other posts.
They should not be used to change the look (style, design) of a particular post though. You can do this with CSS. They should only be used to change how a particular post functions.
Creating the function to handle single post templates
Note that this is an advanced tutorial. You need to know what WordPress filters are and how the template hierarchy works before even considering using this tutorial.
For the sake of this tutorial, all of our additional post templates will reside within a folder named single within our theme folder. So, you’ll have a directory structure that looks like this:
/themes
/your-theme
/single
This will be much more helpful in the long run, especially if you’re creating multiple templates.
Open your theme’s functions.php file and add this:
<?php
/**
* Define a constant path to our single template folder
*/
define(SINGLE_PATH, TEMPLATEPATH . '/single');
/**
* Filter the single_template with our custom function
*/
add_filter('single_template', 'my_single_template');
/**
* Single template function which will choose our template
*/
function my_single_template($single) {
global $wp_query, $post;
Now, we’ve set up everything but haven’t finished. I will take you through the different things you can define your single post templates by now.
In the next steps, you can choose to implement any of these methods, but you don’t have to use all of them.
This first part will check for templates within the /single folder labeled like single-100.php. It’s looking for the post ID. So, if you have a post with an ID that matches the template, it will be loaded.
/**
* Checks for single template by ID
*/
if(file_exists(SINGLE_PATH . '/single-' . $post->ID . '.php'))
return SINGLE_PATH . '/single-' . $post->ID . '.php';
Let’s suppose you want to check for templates by category slug or ID. This part will tell the script to look for templates such as single-cat-uncategorized.php or single-cat-1.php within the /single folder.
/**
* Checks for single template by category
* Check by category slug and ID
*/
foreach((array)get_the_category() as $cat) :
if(file_exists(SINGLE_PATH . '/single-cat-' . $cat->slug . '.php'))
return SINGLE_PATH . '/single-cat-' . $cat->slug . '.php';
elseif(file_exists(SINGLE_PATH . '/single-cat-' . $cat->term_id . '.php'))
return SINGLE_PATH . '/single-cat-' . $cat->term_id . '.php';
endforeach;
Now I will show you how to check for single templates based on the tags used in a post. This will check for a template based on tag slug and ID, such as single-tag-example.php and single-tag-100.php.
/**
* Checks for single template by tag
* Check by tag slug and ID
*/
$wp_query->in_the_loop = true;
foreach((array)get_the_tags() as $tag) :
if(file_exists(SINGLE_PATH . '/single-tag-' . $tag->slug . '.php'))
return SINGLE_PATH . '/single-tag-' . $tag->slug . '.php';
elseif(file_exists(SINGLE_PATH . '/single-tag-' . $tag->term_id . '.php'))
return SINGLE_PATH . '/single-tag-' . $tag->term_id . '.php';
endforeach;
$wp_query->in_the_loop = false;
You may even want to check for single templates by author. Well, we can do that too. This will check for author by user nicename and user ID. So, you can set up templates like single-author-admin.php and single-author-1.php.
/**
* Checks for single template by author
* Check by user nicename and ID
*/
$curauth = get_userdata($wp_query->post->post_author);
if(file_exists(SINGLE_PATH . '/single-author-' . $curauth->user_nicename . '.php'))
return SINGLE_PATH . '/single-author-' . $curauth->user_nicename . '.php';
elseif(file_exists(SINGLE_PATH . '/single-author-' . $curauth->ID . '.php'))
return SINGLE_PATH . '/single-author-' . $curauth->ID . '.php';
And, the final check you can do is for a default single.php or default.php file within the /single folder.
/**
* Checks for default single post files within the single folder
*/
if(file_exists(SINGLE_PATH . '/single.php'))
return SINGLE_PATH . '/single.php';
elseif(file_exists(SINGLE_PATH . '/default.php'))
return SINGLE_PATH . '/default.php';
Once you’ve added whatever code you wanted to inside of your function, you need to close it off.
return $single;
}
?>
How to create a custom post template
Before you begin creating templates, you should ask yourself a few questions?
- What will this template do? What is its purpose?
- When should it be used? In what context?
- Will a WordPress action or filter hook work better?
- Can my goals be achieved through CSS?
I can’t tell you what to actually use your single post templates for, but I can tell you how to create them.
First, you want to create a folder named single in your theme folder if you haven’t done so already. Then, make a copy of your theme’s single.php file and drop it within that folder.
To create a single template based on the category Uncategorized, we would only need to name the file we copied to single-cat-uncategorized.php. Then, all of your posts on their single post view with the Uncategorized category will use that particular template instead of the normal single post template.
You can change the code in your new file to anything. There are no limits. It’s up to you to decide how your template should function though.
Using a child theme?
I know many of my readers are starting to hop on the child-theme bandwagon, and I’m happy about that. You can use this method in your child theme as well.
You only need to change this line in the code above:
define(SINGLE_PATH, TEMPLATEPATH . '/single');
Change it to:
define(SINGLE_PATH, STYLESHEETPATH . '/single');
WordPress 2.7 also has a function called locate_template() that you can use to check for template files that you specify. It will search within a child theme and the parent theme for you. You can see how it works in /wp-includes/theme.php.
Closing thoughts on single templates
You could potentially even do this on a date-/time-based template level, but I figured I’d stop at this point.
I haven’t found any uses for doing this myself, but it is a neat concept to toy around with. Most arguments I’ve seen for using single post templates have been style-based arguments. I strongly suggest using a CSS solution before using additional templates if at all possible.
I’m also thinking of packaging something like this up in a plugin but a more advanced version. Would anyone be interested in that?

Thanks for explaining the template method. I want to create one.
Excellent tutorial. Thanks for sharing your knowledges, Justin!
A tricky topic well explained. Very nice tutorial.
This is so nice. Though I have no clue of why I would need such template, it seems that large news oriented sites may need it for something about BIG event or once-in-a-lifetime article which needs special attention.
This is part of WordPress’s ability which has the sky limit… That is why we love WordPress.
You should definitely throw it out as a plugin. It makes more sense as a plugin than as part of a theme as I think once someone has done this, if they switch themes, they are likely to want to continue that customisation.
I agree, you should do the plugin.
J Mehmett
I don’t see much of a reason to actually use them myself. Most things can be done with CSS alone.
Andrew
That’s what I was thinking as well. It would work better as a plugin. I’d like to expand on it a bit to be a full-blown template loader before putting it together as a plugin.
Hello Justin. I was just looking over the Custom Post Template Plugin at http://wordpress.org/extend/plugins/custom-post-template/ a few minutes ago. I was thinking that I would prefer a non-plugin solution
Thank you for your post!
A good site! What is the name of u theme? I want the same)
@ Justin Tadlock,
True. CSS can be implemented to change the look and feel of certain posts, using post IDs as classes as usual.
But, I thought of how someone would use the technique explained in this tutorial, of course someone may use it when they want to change the normal content of the sidebar, navigation, header, footer, etc… Or when they want to add something extra in the posts template…
Great tip though. I may need it someday.
Could be this done in the rss feed? if yes could you explain it in the next tutorial
btw i was looking for tutorial of this kind of topic a couple of days ago, but none could explain it this better,
thx a lot for the tip
mercime
I’ve never come across that plugin before, but after looking at how it’s used, I prefer this method better.
rastaman
The theme used on this site is a custom theme I made.
J Mehmett
Most definitely. It should only be used to change how a post functions.
Dian
This is for single posts, which is an entirely different thing that your feed. I don’t work with feeds, so I probably won’t be writing any tutorials on them.
Out of curiosity, what would you need something like this in a feed for? This tutorial is about how your theme works.
I’m sorry, what i meant that by reading this tutorial i understand that u could sort a page into certain category post(using string $cat right?), I thought by sorting it, u could divide the site into a new rss feed setting, the new page have another feed sorting but i forgot that this is a SINGLE post template, so my bad
Hi Justin! I’m wondering if you like the idea of having an entry about creating sidebar template for Wordpress?
I liked this post.
Stay fit!
Galwin
I abhor the idea of a sidebar template altogether. The name itself is un-semantic, especially when it’s not actually used for a sidebar. I belong to a group of people in the WordPress community that believes we should kill the sidebar. I didn’t even add a
sidebar.phpto my latest theme. I hope I never have to again.So, that’s a few of my thoughts about creating sidebar templates.
Thanks for your answer, Justin. I read the ‘kill the sidebar’ entry and I feel you now.
Galwin
No problem. I’m just not a big fan of the how sidebars have been used in WordPress.
I think we need to move toward a more semantic naming scheme — modules, asides, sections, whatever.
Andrea
This could be a solution for displaying ads per author. I would suggest looking into an alternative solution such as filtering
the_content()first though.Of course, each author could have access to their own personal file to change things up a bit whenever they wanted to.
I guess it would depend on all the details of the project — who’s in charge, who has access to what, and so on.
Toks
You probably have an error, such as empty space outside of your PHP tags. If not that, then you either have another plugin conflicting with your WP or you made a mistake somewhere.
Justin.
Most interesting article.
Your solution may be exactly what I was looking for.
I’m going to open a blog in collaboration with a couple of friends and we were looking for a way to selectively display adsense ads. Every blog post single page should display only the code relative to the adsense account of the author of the post.
I think your tutorial can solve our problems.
Thanks for the post. I tried and it works but when I make any changes or save/publish it takes me to a blank screen. Do you know why that is?
This it what I was looking for:D
usefull!
I tried it and it goes to blank screen do you have any suggestions how do I make it work please? or should I post the error here?
Thank you
@Desi and others who ask about the white screen/blank page.
It’s easy to fix it. When “function.php” code has been modified occurs some problems whith extra-spaces between the code lines. Just delete that spaces and the Admin will save it as normal.
Michael
I’m glad you found it useful.
desi
This is an advanced tutorial, so you need to be very comfortable working with PHP and WordPress.
However, if you still need help with it, you can sign up for an account to my support forums at Theme Hybrid where we’ll be happy to help you out.
Thanks for the post, but I have a question, how to use your function “my_single_template($single)”? what is $single parameter return. please help.. thanks
Please help.. Fatal error: Call to undefined function add_filter() in C:\xampp\htdocs\wp_cfip\wp-includes\functions-custom.php on line 12
marvs
You’re returning the
$singlevariable as a new template.hi., thanks 4 the reply. I’m a newbie in wordpress, can give me a value for $single parameter (e.g. my_single_template(“?”)). One more question, whay there’s an error occured when i’m trying to call add_filter() function. Thanks again.
Then, you definitely should not be trying this out. That is why I put this note in the tutorial:
I really suggest learning how WordPress works before even attempting something like this.
If you still want assistance in setting this up, you need to sign up for an account at Theme Hybrid for support.
sorry.. I’m newbie in forum, nway i’ve got the solution. thanks 4 the reply again.
- marvs (philippines)
I was just looking for something like this, very useful. What I’m looking to do is a catch-all single post template for subcategories aswell.
You’ve got some awesome tutorials!
Jon Kristian
Thanks. You can definitely use this for sub-categories.
Hi Justin
You wrote “They should not be used to change the look (style, design) of a particular post though. You can do this with CSS.”
J Mehmett also said:
“CSS can be implemented to change the look and feel of certain posts, using post IDs as classes as usual.”
How exactly do I assign different styles in CSS to different template?
For example, I would like to have different styles for different authors, after creating different post templates for each of them.
nice to use it for subcategories!!
This works, but when I try to edit something now I get the following error:
Do you know how to fix this?
Some of this comment was deleted by the admin. Please properly format code before posting it in a WordPress comment section.
This tutorial is for someone who is familiar with wordpress, i want to learn more about
wordpress, but don´t know if i should use it or not, cause sometimes i hear there are
many security risks to use wordpress? Don´t know exactly, so i have to check it before
finding out the clue
Gabriel Lerner — Like I said, you shouldn’t use this just to implement a different style. To style something by different authors, you need a theme that gives you a contextual/dynamic body class such as my Hybrid theme.
Cory Glauner — You should read the WordPress FAQ Troubleshooting.
Dagi — This tutorial is not only for someone that is familiar with WordPress, they need to be a fairly advanced user as well.
Running any software on a self-hosted site comes with security risks. WordPress is probably the best to use to avoid those risks though.
amazing and thank you. when i find some extra time i’m really going to dig into the usefulness of functions.php. wordpress continues to impress me with its flexibility and ease of implementation.
Hey, EXCELLENT little tutorial. very nice and exactly what i was looking for.
quick question: would it be possible to add a Login template to this? I’m not sure how to check for login and integrate it into your existing code. Any thoughts on this? I’d love to be able to rebuild wp-login.php and it would be an excellent addition to the custom template concept.
<>
Justin, can you give us an idea of how to use this technique so that it works with sub-categories? Is it necessary to write a new function?
Many thanks!
Awesome tutorial. I am in the process of designing a site that has 2 top-level categories with different templates, and was trying to figure out a way to give single posts matching templates depending on the top-level category. Since the site has many levels of sub-categories, this was becoming rather difficult. It seems using tag-specific single post templates is much more straightforward than finding a way to get the top-level category and assign a single post template that way. Thanks for the info!
Well, I finally got round to doing this on the few posts that warranted it and its yet another powerful tool you’ve helped us with Justin – a pretty simple, yet elegant solution which I didn’t have to come up with myself! Result. While I say the solutionis simple, by that I mean logical, as opposed to easily made.
Great! Works beautifully and so simple to deploy/organise, many thanks!
Hi all,
I just wanted to notice that there is a very very simple plugin by Ryan Boren that allows you to get that done. Just in case somebody wants to have a look on it I leave here the link: http://allancole.com/wordpress/5/custom-category-post-template-plugin/
Thanks for your good tutorial!!
Javier.
Justin,
Thanks! Your tutorial was very clear. But, I was also curious how this would be done with subcategories. Do I have to add or modify the filter?
I think I just answered my own question if anyone is interested about using your single parent category template to include your subcategories, as well.
Just add another elseif statement:
This was extremely helpful and super easy to implement! Thank you!
Hey, great tutorial. Got this up and running in a little experiment I’m undertaking.
Because many of my posts will have images or extra CSS, I need a tidy way to store these post specific files so my site structure doesn’t become an absolute mess.
What I need to know is how, instead of searching for single-”post ID” inside the folder /single, search for that template file inside a folder with the same post id.
I’m simply not sure how to get the POST ID tag to work inside define(SINGLE_PATH.
Thanks!
A second thought just popped into my head,
How am I able to tell my homepage (displaying just the single most recent post) to call this individual template file aswell?
Scott — I hadn’t thought about sub-categories. I guess that’s because I never use them. Good to know.
Berry Blanton — Yeah, it is pretty simple. Glad you like it.
Marc — Something like this ought to work when you need the folder to have the post ID:
That’s outside of the scope of this tutorial and doesn’t deal with single post templates
You’re a life saver mate! Thanks heaps. This tutorial helped me a lot.
“necessity is the mother of invention”
Ok I want to blog about a video today… I better use my post temp for video!
Now I want to blog about photography… better use my post temp for photo’s!
Now I just want to write a straight forward post… better use the default!
Currently I would have to leave the blog timeline and use pages to accomplish this…
Although all the filter ideas are great… I would simply be happy to see the page templates functionality extended to posts… so I could select a template from a drop down menu as I can with pages…
I would love to use a plugin that can do this…
p.s… I forgot to mention that each post template would have different functionality… i.e… a video post would have an area at the top of the page for the video (using the “simple-video-embedder”) and the photo template would have a similar area for the photo etc…
Hope this makes sense…
“always the last to know…”
Found the perfect plugin…!!!… “Custom Post Template”
http://wordpress.org/extend/plugins/custom-post-template/
The WP community is the best on the web…!!!
http://wordpress.org/extend/plugins/custom-post-template/
The above plugin gave me an error so I decided to use this method and I think it’s the perfect solution for me … plugin free!
I have 3 different single post templates that can be changed at any time with a simple edit of the post tag.
Thanks Justin!
Thanks – been searching around for months for a method. You have suplied it, and done it in a way that I could easily follow and impliment. Thank you.
Hm, I have zero knowledge in PHP.
But I love to design a template..
There one thing that confuse me, your function check for name and ID?
Do you think we need to call both?
Thanks for the answer..
Nice, but how do we make it work with all the posts of a child category. Ex.: I name a single-category-3 and work for my posts on category 3 (Cars). But the child categories posts (Ford, GM, Ferrari) must be the same layout. To make it work I have to copy the file and rename ir several times, everytime I made a change….
This is a terrific tutorial but it allows me to ALMOST do what I want. I’m just wondering, is there a way to make a template for a combination of two tags? I want to include specific custom fields on pages tagged with ‘film’ and ‘review’ and I think your above methods are the closest to the easiest way to achieve this. I may be wrong, but it’s my current course of action.
If I could create a template like single-tag-film-review.php and have it only be used when those specific tags are used, I’d be a ridiculously happy camper. Any help with this would be GREATLY appreciated.
Thanks,
Tyler
Thank you for this article
Thanks Justin! This tutorial is just what I was looking for.
For the people wondering how this might be used, I’m making a portfolio site where each project will have multiple blog posts about it but one post will contain the project summary. I want to have a special template for those summary posts that shows the summary, all the images related to the project, lists all the projects blog posts, and has a unique layout to look like a portfolio rather than a blog. I’ll have a landing page for projects that will query just these summary posts and display them portfolio style.
I’m planning on using a custom field to differentiate the summary posts from the rest so hoping to modify this code for that purpose. Any ideas would be greatly appreciated.
It looks like the Custom Post Template plugin can probably accomplish this but I’d rather code something I can customize and maintain as needed.
Thanks again Justin… Best wordpress info blog I’ve found on the web…
I need template post adding films with using custom fields its realy?
Hi Justin,
I’ve a couple of questions on this approach:
1. Has get_the_tags changed with the 2.8.2 release? I’d been writing my own single post function and got stuck with get_the_tags returning false all the time, when I’ve tried your code it also seems to return false on the get_the_tags call… any thoughts?
2. I notice you set the in_the_loop query property false before calling get_the_tags and then reset it after the foreach loop. I thought that might have been my problem for a while, but it wasn’t
However I’m confused, if you find a tag template you’ll return without ever resetting the in_the_loop flag to false, and if I read this right your using the global wp_query object – can this ever be a problem?
Hey Justin,
You helped me in such a big with this post. So much so I felt like I needed to voice it to you!
Thanks!
Great, clear and useful tutorial, 5 minutes to imply!
Great job.
I have another question about templates, Is there an option to have a category-id.php for a parent category and having all its childs to use it as well?
Thanks so much for this! Was gonna start tearing my hair out to find a way to make this work.
For the categories filtering, how can I make it work for a category and its children? I’m curious to know if that’s possible.
Thanks again!
UNtil now i create every single post from scrap. I thing half of my time spent is in designin.I will try your advice. Thank you
Thank you very much for this. Genuinely. It’s so very useful.
Brilliant!
Solved my problem… and I don’t even know how to code PHP
Thanks for that.
Thanks. Exactly what I wanted. So well explained. Test worked immediately. Hat’s off to you. We are an volunteer journalism site with about 100 writers. We’re going to use it to allow authors to own their page – with their own google ads, donate button, blogroll, rss, etc. Perfect.
Good tute J,
..this is my third time to google this sort of stuff in as many months ..and end up on you blog easch time…
..Ive found the plugin that does most of the first part for me … if only i cud get one to design my new /single-002.php template ! LOL
-Regards,
jamie d
It worked! Fan-frickin-tastic!! Thank’s for the useful tip Justin!
Thanks so much! I’m a Wordpress newb, creating a site for a client with Wordpress as a CMS, not for blogging. Found the plug-in for choosing a single post template, but did not want to rely on the client remembering to choose it when they enter a new post. Your method means they don’t have to think about it.
And I’m not a coder, but I was able to follow your step-by-step directions and get it working a just a few minutes. I found some other instructions elsewhere that seemed like they might be what I need, (http://codex.wordpress.org/Theme_Development#Query-based_Templates), but they did not spell out exactly where to paste the code. I’m sure a lot of people here didn’t need every bit of detail, but I did, so thanks for writing it all out.
Thanks so much for helping me out!
Follow up: I thought I had this working, but when I came back to the site a day later I was unable to login. Just got a blank screen of death after entering login data no matter what I did. After a good hour or so of panic I thought to delete the edited functions file and replace it with an original, and voila I could login again.
I’m wondering what I did wrong. Have you had anyone else report this problem? Looks like I will be doing some reading on the functions file.
Great hack, many thanks for sharing this!
I’m currently using this method on my company’s site. Thanks!
I want to take things up one level, though, and use different templates for a single post depending on the URL (based on category).
Let’s say the default for each post is: /post/foo.html
And I want to use a different template for the private version, which is: /post/private/foo.html
(It serves up different content using different custom fields.)
I can use redirect rules to control access to the private version. The trouble is, each post exists in _both_ categories, so it will always use one or the other as the template. I want to use /private/ only when someone goes to that specific URL. Under this current setup, Wordpress is serving up every /post/foo.html using the private template because it also happens to be in the private category.
Can I fix this with changes to the functions.php file?
In any case, thanks for all your help.
YAHOOO!!!! It WORK!
I search for ways to show different single templates by author, then find your tutorial, follow it, and it work! Save me a lot of time.
Good job Tadlock.
Thanks you.
This looks really useful, thanks for putting it out there.
The use that springs to mind is the scenario I’m trying to implement at the moment- I have a particular category of posts that use custom fields, so I need to have custom templates for displaying the additional meta information for just these particular posts and the archive pages for these posts. Wordpress already seems to have the functionality for custom category templates, but I need to do the same thing at the single-post level, too.
Oh, and I’d love to see a plugin version of this, if you’ve not already made one. I’ve seen a couple of plugins allowing selection of a particular template at the post-authoring stage, but not one that allows custom templates to be used on a per-category basis.
Excellent walkthrough, easy to follow and implement. thanks very much.
i am trying to create a post template so that i can use a set template everytime i add a post for my universities i am listing.
I need to create a template so that when I want to load the individual universities as individual posts I get a custom template to fill in.. the individual unis will be loaded as posts under category ‘university listing’
eg it will load the headings for the post onto the page and i then jsut paste the text into it and save it.
http://www.postgraduatesinsport.com/wp-content/uploads/2010/04/BIRKBECK-UNIVERSITY-OF-LONDON.pdf is an example of the layout of what I want to create. It will appear as a post each time… so basically I need a template designed that me or my staff can use to load unis etc…
Top section will have :
Uni logo, uni contact details
Profile
Courses
Web link
Mid section:
INSIGHT – STUDENT EXPERIENCE
The text will be pasted in so just the header need here…
Would like to have a video inbedded on the right with an interview with the student there… thumbnail video inbedded
Bottom section:
COURSE PROFILE
Age
Men/Women Ratio
Careers Students have gone into
Straightforward really. Just need the headings set into a post template called pageofuniversityposts.php or something like that….
When I then load a post and select this template, it will load the template headings and we just need to paste the text and insert the logo and video and away we go!!
Hiya,
I’m revisiting this excellent tutorial.
Just wondering if you could give me some tips on extending it slightly.
I’d like to also be able to check if the post has a particular custom field value, and use that as the path to a custom single post template.
I’ve tried this:
But it doesn’t seem to work for the custom field value (the category-checking works fine though). Any ideas?
Thanks again for sharing,
a|x
I was about to give up and use a plugin when I found your wonderful tutorial. Thank you for sharing your expertise.
First, I love it. Second, I am WILLING TO PAY for support…
The problem, I have my site set up with custom categories… This page, http://hellodestroyers.com/new/friends/, list all the post from the friends category, and the permalink should connect the user to the appropriate single post, however, it loads the most recent post of that category?
Again I will pay for support?
thanks
jason
Never mind.. I removed from a seperate loop with in the same page and BAAM… good to go.
Thank you very much for posting this – just what I’ve been looking for; to be honest I didn’t realise this was even possible in WordPress. Have now implemented it and it is running perfectly.
Thank you this worked like a charm. See it in action at http://www.rocheport.com/new (while I’m developing) and later simply at Rocheport.com
Thanks again, this was EXACTLY what I was looking for.
Thanks Justin for the amazingly simple tutorial. You never fail to deliver.
In theory, your “single template by ID” statement inside your my_single_template function could be used for pages as well?
If page ID = 2, single-2.php?
This 2+ year-old post was a life saver! Thanks! Spent several hours trying to make a custom post template work — to no avail. I walked through this post step by step, and now my Hybrid child theme has working post templates. Thank you!
By the way, I’m running this on WP Multisite 3.0.3 and it works great!
Hi Justin, I recently find this useful method for post templates and I’m wondering if there is a way to work this trick for me.
So if we have one post in two or more categories and we want to display the post with comments ability in one category and without comments in the other categories. Is this possible?
Thanks
Hey! Great Article, Justin!
What if the element you want to change is not in the single.php file but in the loop.php file? The loop calls the post thumbnail to appear before the post title. But I want, for a specific category, to remove that thumbnail from the loop…
Hopefully I am making myself clear.
Thanks so much for this!
Love this and have used it a few times, particularly for the category-specific templates. With a new site using custom post types though, I am encountering a problem with the default use of single-{post-type} not returning the single template for the custom post type.
How would I modify the code above to maintain the category specific single post templates while also enabling the single post type ones?
Got my question answered on WordPress StackExchange here: http://wordpress.stackexchange.com/questions/13837/conflict-in-function-to-allow-single-post-template-based-on-category
Here’s the code:
and just replace “POST TYPE NAME” with your custom post type name.
This is still great over two years later! Thanks for posting it.
does checking for author by user nicename and user ID work on wordpress 3.1.2?
I’m trying to make this work on twentyten theme. I cant seem to make it work.
Can you upload a theme folder that works on wordpress 3.1.2. I really need the method for checking a template by author.
Thanks
Thanks Scott for your code! But I found a problem, what about sub-sub categories? Or sub-sub-sub-sub categories?
This is the complete code that I added to my functions.php
thanks for this.. I didn’t know it’s so simple.. and I like it simple