Skip navigation

Creating Multiple Single Posts for Different Categories

Tips Apply to the Full Version of WordPress.

UPDATE: While the following technique works, I recommend it only as an extreme measure. I now recommend following the techniques in Conditional Tags on the WordPress Codex. Use the is_category or one of the other conditional tag options to create a stylesheet or web page customization for the condition you wish to change such as having the sidebar only on the front page of the site and not on the single post pageviews, or having a blue background on the Apple category and the green background for the Orange category. This will serve you and maintain your site longer than the following example.


I had a unique challenge. I needed to assign a specific stylesheet for only one category of blog posts in a WordPress blog. There are a lot of ways of doing this, but I wanted it to be fast and simple. I choose to use a WordPress conditional tag to check which category the blog post was in, and then change the header of the post to the one with the customized stylesheet for that particular category.

My very popular series on CSS Experiments in Design consists of almost a dozen pages with hundreds of different design experiments. Most of these feature inline styles, but a lot of them had their own styles in a separate stylesheet. The stylesheet was huge. With about a thousand articles on my site, why should I include over 30K of styles in my site’s default style sheet when I only need them for a handful of articles?

I needed a way to let the style sheet for the CSS Experiment pages only appear on those web pages and not the rest of the site. This is one method. In Using WordPress Categories to Style Posts, guest blogger, Abhijit Nadgouda of ifacethoughts, explains a similar method that might be easier for some.

With only one header template in my WordPress Theme, and the conditional tags saying “if this is a single page, show the single page”, I needed something that said:

If this is a single page in the X category
show the single page with these styles added.

By default usage, the WordPress Template Hierarchy states that when you click a link to a single post page, WordPress will automatically look for the single.php template file and if it doesn’t find it, it will look for the index.php and return the information in there for displaying a single post.

What I wanted was to throw a condition in the single.php that says “if this post belongs to the X category, do something different.”

The If in_category Conditional Tag

The process began by making two back up copies of the single.php page called single1.php and single.2.php.

Inside of the original single.php, delete everything and replace it with this:


<?php
$post = $wp_query->post;
if ( in_category('9') ) {
include(TEMPLATEPATH . '/single2.php');
} else {
include(TEMPLATEPATH . '/single1.php');
}
?>


In the most simple terms, the PHP code issues a query that says:

Check the post. If the post is in category ID number 9, display single2.php. If not in category ID number 9, display single1.php.

In the in_category(), we set the category ID number to 9, the one that holds all of my web page design articles and experiments. When the user visits any post within that specific category, the custom stylesheet is used for those blog posts.

This is just the start of what you could do. To showcase different results in different categories, you could create a long list of conditions like this:

<?php
$post = $wp_query->post;
if ( in_category('9') ) {
include(TEMPLATEPATH . '/single9.php');
elseif ( in_category('12') ) {
include(TEMPLATEPATH . '/single12.php');
elseif ( in_category('42') {
include(TEMPLATEPATH . '/single42.php');
} else {
include(TEMPLATEPATH . '/single1.php');
} }
?>

In my two “single” copy template files, I put a comment code in the top of each one with a number as a reminder of what each one was to do, like this:

<!-- single 2 - for CSS Web Page Articles -->

Since I don’t want to change these two different single post templates, just add the additional style sheet to the second one, I created two header template files, exact copies like with the single.php, with an extra style sheet link in the top of the second one.

Inside of header2.php in the head section, I added the second style sheet link:

<style type="text/css" media="screen">
@import URL('/wp-content/themes/mytheme/style.css');
@import URL('/wp-content/themes/mytheme/cssstyles.css');
</style >

In the new single.2.php template file, I changed the GET for the header to get the header2.php:

<?php
/* Don't remove this line. */
require('./wp-blog-header.php');
include(get_template_directory() . '/header2.php'
?>

To test this, I uploaded all the files and clicked on any post NOT within category 9. Clicking View Source in the browser, I hunted for my comment tag and “single 1” or “single 2” in the code to see which “single” template was used. If it worked, I should see a comment that says:

<!-- single 1 - for all the rest of the pages -->

If I see “single 2” then something is wrong.

Then I clicked on a single post IN category 9 and did the same thing. There I should see the comment that this is indeed “single 2” and the two style sheet links should be in the header as proof that everything is done right.

There are many ways of doing this, as the PHP and conditional tags and template files used by WordPress are so versatile, but this was very easy to do for someone who is lacking in much PHP skill, though I’m learning the hard way. From this, you can make as many single post page looks as you want, as long as they are styled by their category.

Here are some other resources that will help you with WordPress queries and the WordPress Loop, as well as developing, designing, and customizing your WordPress Theme.

Member of the 9Rules Blogging Network


Site Search Tags: , , , , , , , , , , , , , , , ,
Feed on Lorelle on WordPress Subscribe Feedburner iconVia Feedburner Subscribe by Email

Copyright Lorelle VanFossen, member of the 9Rules Network, and author of Blogging Tips, What Bloggers Won't Tell You About Blogging.

83 Comments

  1. Posted September 26, 2005 at 6:05 am | Permalink

    Thanks a lot for this post. I missed the function
    in_category() and did some strange things to get the different customized posts. I have to rewrite lots of pages soon, since this is faster.

    I’m waiting for a
    switch($category){
    case ‘1’:
    require(“post1.php”);
    break;
    case ‘2’:
    require(“post2.php”);
    break;
    default:
    require(‘post.php’);
    break
    }

  2. Posted June 9, 2006 at 8:31 am | Permalink

    Just thought I’d drop you a line to say, this WordPress article really saved my bacon on the appropriate commands for issuing a second call to a different header file to the WordPress hard-coded one. Very, very appreciated, easy to understand, the code samples in particular came in very handy. Ahh, if only all tutorials were like this one. Keep up the good work!

    Cheers!
    Martin K.
    Australia
    http://www.urbanzombies.com

  3. Posted October 12, 2006 at 3:47 pm | Permalink

    Thank you, this one had me stumped for a little while, I appreciate the tutorial!:)

  4. Posted April 18, 2007 at 11:09 am | Permalink

    Thanks for the helpful tutorial. This is exactly what I was trying to do, and couldn’t figure out how to have more than one header file.

  5. Rob
    Posted September 4, 2007 at 9:37 am | Permalink

    This is exactly what I have been looking for, but I kept skipping it in Google because the title didn’t seem to be the right thing…

  6. Posted September 30, 2007 at 11:04 pm | Permalink

    Thank you for the article and it really saved my day.

    Just small remark I believe there are some missing closing braces or curly brackets before each elseif in the second php post query.

    Great blog and thanks again.:):):).
    I will keep coming to your blog and hopefully participate.

  7. Posted October 1, 2007 at 12:18 am | Permalink

    Thanks. For two years, no one noticed this. Thank you!!!!

  8. Posted October 11, 2007 at 7:58 am | Permalink

    Perfect. This really helps with my twitter posts!

    • Hafiz
      Posted June 6, 2011 at 1:15 am | Permalink

      Can u help me about what is page.php in wordpress.
      i don’t understand what is the difference b/w single.php and page.php

  9. Posted November 18, 2007 at 8:16 pm | Permalink

    Thanks for the tip, like Mohamed says, the code for the second query has some missing brackets, here’s the working code 🙂

    post;
    if ( in_category('1') ) {include(TEMPLATEPATH . '/single1.php');}
    elseif ( in_category('2') ) {include(TEMPLATEPATH . '/single2.php');}
    elseif ( in_category('3') ) {include(TEMPLATEPATH . '/single3.php');}
    else {include(TEMPLATEPATH . '/single1.php');}
    ?>

    cheers, and thanks again, and again…

  10. Posted November 28, 2007 at 2:41 pm | Permalink

    Thanks for this tip. I am using it to display one of two different sidebars, depending upon the post category.

    Initially the code didn’t work for me–I had to change “in_category” to “is_category.” Now it works like a charm!

    Thanks for all your great articles. Your blog is on my WP hot list now!

    Adrienne

  11. Posted November 28, 2007 at 3:22 pm | Permalink

    @Adrienne:

    Interesting. There are two Conditional Tags in WordPress that deal with categories: in_category and is_category. The first one asks if this “is the category” and then responds accordingly with the command. The second one asks if the post is “in the category” and responds. This worked for me in older versions of WordPress and I will be running new tests on this code in new versions soon, so I’ll double check that.

    Either one should work in this instance but I’ll look into this more. Thanks!

  12. Posted November 28, 2007 at 4:17 pm | Permalink

    Lorelle,

    Thanks for your reply. As I am still trying to work this out I am having mixed results with both methods. Part of the problem may be that I am trying to use two separate post sections and create sidebars that only pull up items for the separate areas. To do this I’ve created two large categories, let’s say a “Blog” category & a “Reviews” category, then put everything else in subcategories of Blog or Reviews. The test site resembles a traditional static site, with mostly static pages (including a static homepage), and includes these two separate posting categories as pseudo-pages.

    It’s a bit of a stretch given my rather limited ability with WP, but I’d really like to make it work as I think the project has potential.

    Adrienne

  13. Posted November 28, 2007 at 4:42 pm | Permalink

    @Adrienne:

    Just remember, you don’t have to break the wheel to invent the wheel. Forcing a blog into a “traditional” static website defeats the benefits of a blog. And too many bloggers and designers put too much emphasis on the front page when people land most on single post pages.

    Good luck, but consider going forward instead of backwards in your web design.

  14. Posted November 28, 2007 at 5:27 pm | Permalink

    Lorelle,

    Your observations are very much appreciated. The site I’m creating isn’t a blog per se–it has blog-like elements, but it’s primary purpose is not as a blog. Whether or not the site has a static front page isn’t the issue I’m terribly invested in, anyway. What I’m looking for is a way to use WP to deal with a certain amount of a site’s information dynamically without having everything dumped into one big “blog bucket.” Perhaps I AM breaking the wheel here–I like to think of it more as exploring the possibilities of WP as it can be combined with/adapted to more traditional website structure.

    See the comments in trackback No. 1, above–what I’m looking for is very similar to what that person is describing. I actually have two clients right now who want to utilize a “separate but equal” policy with a certain amount of their dynamic site content, and as I have been researching this I’ve found several other folks who are looking for exactly the same thing. So I see a need for this, at least with what I’m working on these days.

    Thanks again,

    Adrienne

  15. Posted November 28, 2007 at 7:56 pm | Permalink

    What the trackback is talking about is common and explained here and in the WordPress Codex article on Conditional Tags, as well as elsewhere in the Codex, the online manual for WordPress users. You’ll find it is a very common usage, if what they describe is what you are looking for.

    Good luck with it and let me know how it turns out.

  16. Posted January 1, 2008 at 8:05 am | Permalink

    Lorelle, thank you so much for clearly and concisely describing the problem and solution. I just began working with WP on a pro-bono project for a local charity, so I am very interested in quick and elegant solutions to minimize my non-billable hours. I am very thankful to have found your site. I easily implemented your suggestions to produce a consistent interface for single posts, by specific category. This was done in conjunction with specific page templates and sidebar templates, in order to present a consistent interface for each type of category.

  17. Posted February 6, 2008 at 11:33 am | Permalink

    I used this technique and accomplished exactly what I needed. It’s super handy for calling alternate pages outside of The Loop.

    Now my question is, is there a way to make this work for multiple categories? in_category doesn’t seem to work except for single categories. I tried:

    post;
    if ( in_category(14) && in_category(3) ) {
    include(TEMPLATEPATH . ‘/single_current.php’);
    } else {
    include(TEMPLATEPATH . ‘/single_back.php’);
    }
    ?>

    But it didn’t seem to work. Is there a way to call multiple categories using this technique? Any tips would be greatly appreciated!

  18. Posted February 6, 2008 at 3:33 pm | Permalink

    The examples for how to use multiple in_category examples is found on the WordPress Codex Template Tags in_category article.

  19. Posted February 20, 2008 at 12:06 pm | Permalink

    This worked great my category page here Lorelle! (http://fbcwaynesboro.org/archives/category/sermons)

    One additional thing trying to figure out is changing the url structure a little. (changing term category to articles…)

    Can permalink structure be set to load without the default “archive” without throwing everything off?

  20. Posted February 20, 2008 at 4:14 pm | Permalink

    @ David Stembridge:

    See Using Permalinks for more information on this, and if you are using the latest version of WordPress, it now features automatic URL redirects to redirect content around if you change your permalink structure.

  21. Posted March 27, 2008 at 11:45 am | Permalink

    Thanks for this article. I couldn’t for the life of me figure out how to display different comment pages. So instead of using it for the single.php, I’m using it for the comments.php. Some of my categories I have set up for reviews and this works great for giving a different look based on category id.

  22. Posted May 1, 2008 at 12:53 pm | Permalink

    Hi, on the question “How to make multiple categories?” Here is the way:

    if ( in_category('23') || in_category('830') || in_category('828') || in_category('829') ) {
    include(TEMPLATEPATH . '/single1.php');
    } else {
    include(TEMPLATEPATH . '/single2.php');
    }

  23. Posted May 1, 2008 at 2:13 pm | Permalink

    @ Igor aka prodigy2m:

    This is the new method that works with new versions of WordPress. The method in the article is for the very oldest versions of WordPress. 😀

    Also, in the future when posting code in comments and blog posts, please read Writing and Publishing Code in Your WordPress Blog Posts for tips.

  24. Shane10101
    Posted May 26, 2008 at 8:39 pm | Permalink

    Hi Lorelle! I’d like to go a step further, and apply a different template to posts in a specific category.

    Here’s what I’m trying to do: I have an About page for a think-tank, which lists, below the usual about info, a list of the group’s experts & a short bio for each. What I’d like to do is link each person’s name/photo to a “page”, with a more complete bio & list of published works. I decided to go with “posts” instead of pages for each expert, because it seemed simpler to deal with. (I could be wrong; definitely open to suggestions.)

    So, for every post in the “experts” category (category 6), I’d like the template used to display just one post, and none of the usual metadata or the comment form. I first tried to create a category-6.php file, but that’s only called when I click on the “experts” category; the posts themselves come up under the usual single.php template.

    How can I make all posts in a given category display in a given template??

    Thanks for your tireless assistance to all us aspiring WP-Pros! 😉

    Shane

  25. Posted June 1, 2008 at 7:25 pm | Permalink

    @ Shane10101:

    Author Templates in the WordPress Codex will help you solve much of this issue. I always start with the WordPress Codex, the online manual for WordPress Users, for technical help with WordPress. 😀

  26. fntn
    Posted June 17, 2008 at 6:12 am | Permalink

    Has anyone encountered pagination problems when using this technique?
    i am using this technique for category pages as well as single post pages which is where i’m having the problem

  27. Posted June 28, 2008 at 3:48 am | Permalink

    I had pagination problems when excluding some categories from my “index.php”. The pagination simply disappeared. I solved the problem by commenting out the old “wp-pagenavi” code in my “functions.php” and installing it as a plugin instead.

  28. Proxy-
    Posted September 3, 2008 at 12:15 pm | Permalink

    Outstanding I have mods installed that made certain page like standard posts have items that should not have been there. With this work around it fixed the problem perfectly.

    Thank you for suppling this

  29. Posted September 4, 2008 at 5:23 am | Permalink

    thank you, i will try it on my blog, wordpress is really capable of doing everything!

  30. Deena
    Posted October 21, 2008 at 7:22 am | Permalink

    Thank you, thank you, thank you. Once again, you are my hero.

  31. Posted November 17, 2008 at 7:43 am | Permalink

    thanks for your informative hack I used the simple one
    post;
    if ( in_category(‘9’) ) {
    include(TEMPLATEPATH . ‘/single2.php’);
    } else {
    include(TEMPLATEPATH . ‘/single1.php’);
    }
    ?>
    and with the help of the category-9.php implementation everything is fine for single and categories I have unique presentation for my 2 major things of my site news and products the problem is how can I change the first page index.php in order to show differently news and products.

  32. Posted November 18, 2008 at 9:27 am | Permalink

    This post was a LIFESAVER for me! Thank you so much!

  33. Posted November 25, 2008 at 10:17 am | Permalink

    Thanks so much, this was super handy! Just what I needed and easy to implement. You should have seen the ridiculous code I was trying to use to generate the page with a jillion if/then conditionals for the category haha.

  34. Posted November 30, 2008 at 9:10 am | Permalink

    Just exactly what I’ve been looking for.
    I’m trying to somewhat “combine” the themes that I am using right now. A few fixes in each themes CSS and I can have, let’s say for example, a total cool Single Post Template for Photos and a regular one for normal posts 🙂

  35. Posted December 23, 2008 at 3:40 pm | Permalink

    There’s a plugin that’s been out there for a while that does something similar… it allows you to create a custom single template for all posts within a specific category. It’s very easy to use. You can find it at http://guff.szub.net/2005/07/21/post-templates-by-category/.

    I’ve been using it for a long time now, and it works with the latest versions of wordpress (for me anyway).

  36. Posted December 30, 2008 at 2:34 am | Permalink

    Great.Thank you very much

  37. Reino
    Posted April 5, 2009 at 3:28 am | Permalink

    Thanks for this simple but usefull solution!!

  38. Posted June 12, 2009 at 2:57 am | Permalink

    much more elegant than the solution i was brewing in my head! thanks

  39. OPW
    Posted June 12, 2009 at 2:58 am | Permalink

    Fantastic post and solution. I had installed a plug-in to do this (which worked really nicely, incidentally). It would have been fine if I was the only user of the site, but it’s a shared CMS-like site and I’m certain some users would never remember to select the correct template. This nicely takes the choice out of the contributor’s hands and automates the whole process. Thank you and keep up the good work!
    Chris

  40. Posted August 10, 2009 at 8:17 pm | Permalink

    Try the body_class() and conditionals now people.

    Goood post though, prompted me to rethink what I was going to do.

    Thanks,
    L

  41. rodrigo
    Posted January 29, 2010 at 5:10 am | Permalink

    thanks so much… save my life!

  42. Toby
    Posted April 2, 2010 at 11:05 pm | Permalink

    Hi Lorelle,

    Thank you for the post.. it’s brought me so much closer to what I’m trying to achieve.

    I’ve been at this for days now and it’s driving me nuts.. I was wondering is there some way to make this apply to the multiple post display of a category? For example you say you have a category called NEWS, when somebody clicks on it, it shows the excerpts of all your posts. I want to change this page on my blog to show a different sidebar then all my other posts. I’ve been able to use your tutorial to change the single post’s sidebar but not the multiple post view of the category.

    Is there some php code to add? Or somewhere to look?

    Thanks,
    Toby

  43. Toby
    Posted April 3, 2010 at 3:03 am | Permalink

    I finally found the answer: http://codex.wordpress.org/Category_Templates

    You’re fix still came in helpful.. thanks!

  44. Posted July 21, 2010 at 9:22 pm | Permalink

    Thank you for the tutorial! What would the code look like if I wanted it for pages not posts?

    Where would I place the code?

    Thank you, again.

    • Posted July 22, 2010 at 8:18 am | Permalink

      This is older tech so if your Theme is set up to use page names in the CSS for a top container like <body>, you can just add CSS for that page name.

  45. Posted July 22, 2010 at 12:51 pm | Permalink

    Thank you for your reply but I’m not sure what you mean. I’m not a programmer/designer but I can follow directions well if you can please help me.

    The issue: I places a slider code on my page.php because that’s what the set up required for it to work but there are some pages I don’t want the slider on, like the “about” page.

    How do I exclude the slider from the about me page or any other page I don’t want it on? I was trying to wrap my head around your tutorial so I could apply the concept to the “page” thing versus “post” scenario but I got in deep and needed a hand.

    I’m usind WP 3.0.

    • Posted July 23, 2010 at 4:53 pm | Permalink

      Are you asking to hire me? 😀 You will have to contact the site and people who developed the slider code and follow their instructions. The WordPress Codex and WordPress Support Forums are great resources.

  46. Posted July 27, 2010 at 9:23 pm | Permalink

    Yes. I’m asking to hire you, but not for the slider for the coding project. I’d like to learn this stuff. At least enough to put together a decent site. There is SO MUCH info out there I don’t know where to start to get done what I need done. With a teacher I’m assured to get my questions answered. So what do you say…

    • Posted July 28, 2010 at 9:54 am | Permalink

      Thank you for the offer. I offer a variety of training workshops and programs, traveling around the world to work with companies, but I do not offer individual training programs. My consultancy and training work is booked for the next several months. I understand your dilemma, which is why I run this blog, offering basic tutorials on WordPress and blogging. Please see Learning About Blogging and How to Blog for a basic start. Also check out Darren Rowse on Problogger for some excellent advice on running a blog for your business. Thanks again.

  47. Posted August 23, 2010 at 11:49 pm | Permalink

    Thanks!! This simply helped me make those multiple single.php templates for posts in those categories. The article was immediately helpful and stated very eloquently.

  48. Posted November 27, 2010 at 8:19 pm | Permalink

    Lorelle,

    Great post! Took me a while digging around google but this helped a lot.

    What if I wanted to generate the same post twice? One full post and then the same post with a different url that is styled completely differently and just contains one piece of meta data from the original post.

    Any ideas of how I could go about this?

    Many thanks!

    • Posted November 29, 2010 at 4:33 pm | Permalink

      Same post twice? I don’t understand, but I’m sure it is possible with a customized single.php or something like that with the template tags you desire in the WordPress loop.

  49. pop n fresh
    Posted December 4, 2010 at 1:29 am | Permalink

    Help, the codes work fine however with my custom archive page, it doubles up on the content, it has the content that is customised then after it’ll show the same content as it would normally be shown??

    what is wrong?

    • Posted December 4, 2010 at 11:04 am | Permalink

      Then you haven’t followed the instructions fully. This shouldn’t impact your posts as it just offers a switch to a different template file, not a change to the WordPress loop.

  50. MKC
    Posted December 6, 2010 at 10:20 am | Permalink

    Well I tried this method and after about an of going round and round I discovered that in a child theme you have to use STYLESHEETPATH. I still can’t get it to do what I want, but I at least found that out.

  51. martin
    Posted December 6, 2010 at 2:53 pm | Permalink

    What should I do if it’s a child category?

    • Posted December 6, 2010 at 5:17 pm | Permalink

      You use the category ID number, which doesn’t care if it is a parent or child theme.

  52. MKC
    Posted December 6, 2010 at 11:58 pm | Permalink

    Well, I’m persisting with this but still no luck

    post;
    if (in_category( 8 )) {
    include(STYLESHEETPATH . ‘/single02.php’);
    } elseif (in_category( 23 )) {
    include(STYLESHEETPATH . ‘/single03.php’);
    } else {
    include(STYLESHEETPATH . ‘/single01.php’);
    }
    ?>

    My child category (23) is a sub-cat of (8). This only used single02 or single01. I tried it by adding this line:

    if (in_category( 8,-23 )) {

    And that made it default to single03. I thought I had it then, but it also stoppede using single02.php! I guess that’s because I did somthing wrong in the code.

  53. matin
    Posted December 7, 2010 at 6:16 am | Permalink

    I think this time, I have it nailed. I got a bit of a nudge (i.e. the answer) from a WP Sitepoint forum. By changing the order so that the child category comes before the parent category in the list, it does what I want it to.

    I have no idea why of course, and would love to know but for now, I am really happy that it’s very close to what I want.

    Thanks for a neat tip.

    Martin

    • Posted December 7, 2010 at 11:50 am | Permalink

      Don’t know why the order would change things relative to parent and child categories, but if it works for you, great. Thanks for letting me know.

  54. MKC
    Posted December 7, 2010 at 12:44 pm | Permalink

    Well, I’m not much good with the code but the way I understood it was that if the parent category is looked for first, then the child of that parent will still go with that becuase it is still in that category. If the child category comes first then it will use that template before PHP works out who it’s Momma is!

  55. smallbusinessdoer
    Posted January 3, 2011 at 12:05 pm | Permalink

    Awesome, worked like a charm!

  56. simon
    Posted April 14, 2011 at 12:39 pm | Permalink

    Is it possible to do this with comments as well? Tried this, but didn’t work out to well 😦

    comments;
    if ( in_category(‘6’) ) {
    include(TEMPLATEPATH . ‘/comments_review.php’);
    } else {
    include(TEMPLATEPATH . ‘/comments_post.php’);
    }
    ?>

    • Posted April 14, 2011 at 12:52 pm | Permalink

      I don’t know what the comments review thing is supposed to do, but it should work in theory. Double check that all the code, parentheses, commas, apostrophes, are all correct.

  57. Kavlexster
    Posted September 26, 2011 at 2:34 am | Permalink

    Hi nice tut !!!

    On problem, when i use Multiple Single Posts i have one white space on top screen ??? Can you help me to solve this ?

  58. Alan
    Posted December 8, 2011 at 4:03 pm | Permalink

    How would you go about doing this by taxonomy? You might not always want to use a custom template for a post just because it is categorized similarly.

    • Posted December 8, 2011 at 8:18 pm | Permalink

      You use the conditional tags that include custom taxonomies and custom post types.

    • Alan
      Posted December 9, 2011 at 10:37 am | Permalink

      Thank you. I’m not sure exactly what you are referring to though, I’m not able to use custom post types for this situation if that is what you are suggesting.

      • Posted December 9, 2011 at 8:37 pm | Permalink

        I thought that was what you were talking about. I’m no unclear as to what you need, but check the Conditional Tags page on the WordPress Codex for a variety of examples that might help.

    • Alan
      Posted December 18, 2011 at 11:24 am | Permalink

      I was trying to say that just because the subject of an article is the same as a category that you have a custom template setup for using the method you have shown above, it doesn’t always mean you want to use that template, but you still would like the article to be listed in that category of content for when people are searching through your site.

    • Alan
      Posted December 18, 2011 at 11:29 am | Permalink

      I’ve since given up and switched to just doing everything by category anyways, but I do have another question if you could help me, I would like all child categories to share the same template. I’ve tried post_is_in_descendant_category function but that didn’t seem to work.

      • Posted December 18, 2011 at 9:26 pm | Permalink

        If you would like an article to be in two categories, select the two categories. The above method is not required for that. It’s a WHOLE different method. I don’t recommend this except for very rare situations as the one I struggled with.

        If the method for child categories isn’t working, then use the conditional tags for each specific category name or ID number in a list within the conditional tag code. As I mentioned earlier, there are examples in the Codex. Someone on the WordPress Support Forum may be able to help you figure out what you might not have right in your code, too. Good luck with it.

    • Alan
      Posted December 18, 2011 at 11:25 pm | Permalink

      What method for child categories are you referring to?

    • Alan
      Posted December 19, 2011 at 8:38 pm | Permalink

      Thank you. Those pages only refer to ways of manually adding one child category at a time though, where I would like (if possible) to setup an automatic deal, so if a month from now I add a new type of food under my food category, it will automatically pick up the special food template also.

  59. Tranh nghe thuat
    Posted March 12, 2012 at 8:40 pm | Permalink

    cool but Can I have customize for category.php ?

    • Posted March 12, 2012 at 9:59 pm | Permalink

      Using conditional tags, you can set the is_category query to anything you want or use the automatic template hierarchy feature and number your category template files to create custom category look and feel.

  60. gvino
    Posted August 7, 2013 at 10:42 pm | Permalink

    Thank you. And i have one question.
    I’m create One Single post and select two different categories. categories1, categories2
    1.www.sitename.com/categories1/Postname
    2.www.sitename.com/categories2/Postname
    And create two template. Single1, Sigle2
    Now I’m click first link and show first template Single1
    And ow I’m click second link but show first template Single1
    It’s possible show second template Single2.
    Please help me.

  61. Posted November 25, 2013 at 7:36 am | Permalink

    Thank you so much for sharing this valuable information. It worked like a charm! YAY!


80 Trackbacks/Pingbacks

  1. […] So, on to implementation. The Village Church uses Pages pretty extensively for our static content (such as the About section), which were able to reproduce the pretty URLs we had set up with the old site. Aside from the Contact form I mentioned above, the News and Sermons are the only Post content we have on the site. We’re using Categories to determine where a post should appear: if it’s News, drop it on the homepage, if it’s a Sermon, drop it in the Sermon archive. We also have put conditions in the individual archive pages to change the display, based on what category we’re looking at (here’s a helpful article on that). That way, Sermons and News items don’t look like each other. We’ve also set up a Featured category (which is a child of Sermons) which floats a copy of the sermon information to the top of the page, making it easy to feature or un-feature content. There is also a little include file that show the latest Sermon on the homepage (using WPDB). […]

  2. […] the matter were knee-deep in code and long scripts. Finally, I found this post by Lorelle on "Creating Multiple Single Posts for Different Categories" which was tremendously useful. However, I still found the explanation a bit fuzzy. I sorted […]

  3. […] to be style1.css, and the stylesheet of the “Tutorials” category to be style2.css. Lorelle provides a simple solution by following the directions […]

  4. […] 分类下面的日志使用style1.css样式表, 而 “Tutorials”分类使用style2.css样式表. Lorelle […]

  5. […] in a category. Ugh, there went my custom sidebars and headers. I then altered my single.php file according to Lorelle and created three single templates for each of the three categories (sidebar-6.php, sidebar-8.php, […]

  6. […] Creating multiple single posts for different categories […]

  7. […] Creating multiple single posts for different categories […]

  8. […] Crea multiples posts para diferentes categorías […]

  9. […] 27. Crear post múltiples para diferentes categorías […]

  10. […] Creating multiple single posts for different categories […]

  11. […] Crea multiples posts para diferentes categorías […]

  12. […] Crea multiples posts para diferentes categorías […]

  13. […] 27. Creating multiple single posts for different categories […]

  14. […] Creating multiple single posts for different categories […]

  15. […] Crea multiples posts para diferentes categorías […]

  16. […] He encontrado unos trucos muy iteresantes para modificar el wordpress aqui, de donde me ha resultado muy util uno en especial, el de cargar distintas hojas de estilo según la categoría. […]

  17. […] Creating multiple single posts for different categories […]

  18. […] categories. I won’t give any further instructions; you’ll find everything you need in this beautiful tutorial by Lorelle. 2. Styling certain single postsI won’t explain this technique either, because Jean-Baptiste […]

  19. […] 27.为不同的分类创造不同的单独日志页面 […]

  20. […] Creating multiple single posts for different categories […]

  21. […] Creating Multiple Single Posts for Different Categories […]

  22. […] Creating multiple single posts for different categories […]

  23. […] it would be better to have another template for the posts in the “news” category. I found a smart solution, you will need to put only the code below in your single.php file in your current theme folder: […]

  24. […] it would be better to have another template for the posts in the “news” category. I found a smart solution, you will need to put only the code below in your single.php file in your current theme […]

  25. […] 27.为不同的分类创造不同的单独日志页面 能为你发表到WordPress博客不同分类的文章定制各自特定的样式。 […]

  26. […] be better to have another template for the posts in the “news” category. I found a smart solution, you will need to put only the code below in your single.php file in your current theme […]

  27. […] it would be better to have another template for the posts in the “news” category. I found a smart solution, you will need to put only the code below in your single.php file in your current theme […]

  28. […] Creating multiple single posts for different categories […]

  29. […] be better to have another template for the posts in the “news” category. I found a smart solution, you will need to put only the code below in your single.php file in your current theme […]

  30. […] Creating multiple single posts for different categories […]

  31. […] Creating multiple single posts for different categories […]

  32. […] Today, while trying to customize the single.php template for a specific category I found a pretty old article written by Lorelle: Creating Multiple Single Posts for Different Categories « Lorelle on WordPress. […]

  33. […] my previous post I talked about a Lorelle blog post on creating single post templates for different […]

  34. […] Crea multiples posts para diferentes categorías […]

  35. […] 27.为不同的分类创造不同的单独日志页面 […]

  36. […] Creating multiple single posts for different categories […]

  37. […] Creating Multiple Single Posts For Different Categories […]

  38. […] Creating multiple single posts for different categories […]

  39. […] Crea multiples posts para diferentes categorías […]

  40. […] Crea multiples posts para diferentes categorías […]

  41. […] it would be better to have another template for the posts in the “news” category. I found a smart solution, you will need to put only the code below in your single.php file in your current theme […]

  42. […] 分类下面的日志使用style1.css样式表, 而 “Tutorials”分类使用style2.css样式表. Lorelle […]

  43. […] it would be better to have another template for the posts in the “news” category. I found a smart solution, you will need to put only the code below in your single.php file in your current theme […]

  44. […] it would be better to have another template for the posts in the “news” category. I found a smart solution, you will need to put only the code below in your single.php file in your current theme […]

  45. […] 27.为不同的分类创造不同的单独日志页面 […]

  46. […] 27.为不同的分类创造不同的单独日志页面 […]

  47. […] it would be better to have another template for the posts in the “news” category. I found a smart solution, you will need to put only the code below in your single.php file in your current theme […]

  48. […] 27.为不同的分类创造不同的单独日志页面 […]

  49. […] Creating multiple single posts for different categories […]

  50. […] Crea multiples posts para diferentes categorías […]

  51. […] Creating multiple single posts for different categories […]

  52. […] 24. Creating Multiple Single Posts for Different Categories […]

  53. […] 27. Creating multiple single posts for different categories […]

  54. […] 而 “Tutorials”分类使用style2.css样式表. Lorelle […]

  55. […] Creating multiple single posts for different categories […]

  56. […] 27.为不同的分类创造不同的单独日志页面 […]

  57. […] it would be better to have another template for the posts in the “news” category. I found a smart solution, you will need to put only the code below in your single.php file in your current theme […]

  58. […] 24. Creating Multiple Single Posts for Different Categories […]

  59. […] Creating Multiple Single Posts for Different Categories […]

  60. […] it would be better to have another template for the posts in the “news” category. I found a smart solution, you will need to put only the code below in your single.php file in your current theme […]

  61. […] ( En castellano)Utiliza Writely para escribir en tu BlogAñade Adsense en el primer post del blog.Crea multiples posts para diferentes categoríasUsando los “Custom Fields” del panel de escrituraCrea un indice de tu históricoMinimiza tu […]

  62. […] Creating multiple single posts for different categories […]

  63. […] 分类下面的日志使用style1.css样式表, 而 “Tutorials”分类使用style2.css样式表. Lorelle […]

  64. […] tutorial might be […]

  65. […] of advice from ‘lorelle‘ the ground […]

  66. […] 分类下面的日志使用style1.css样式表, 而 “Tutorials”分类使用style2.css样式表. Lorelle […]

  67. […] category to be style1.css, and the stylesheet of the “Tutorials” category to be style2.css. Lorelle provides a simple solution by following the directions […]

  68. […] 27) Creating multiple single posts for different categories […]

  69. […] be better to have another template for the posts in the “news” category. I found a smart solution, you will need to put only the code below in your single.php file in your current theme […]

  70. […] it would be better to have another template for the posts in the “news” category. I found a smart solution, you will need to put only the code below in your single.php file in your current theme […]

  71. […] Creating multiple single posts for different categories Fast and simple way to assign a specific stylesheet for only one category of blog posts in a WordPress blog. […]

  72. […] https://lorelle.wordpress.com/2005/09/22/creating-multiple-single-posts-for-different-categories/ […]

  73. […] Creating Multiple Single Posts for Different Categories […]

  74. […] Creating Multiple Single Posts for Different Categories […]

  75. […] Creating Multiple Single Posts for Different Categories […]

  76. […] Creating Multiple Single Posts for Different Categories […]

  77. […] Creating Multiple Single Posts for Different Categories […]

  78. […] Creating Multiple Single Posts for Different Categories […]

  79. […] 分类下面的日志使用style1.css样式表, 而 “Tutorials”分类使用style2.css样式表. Lorelle […]

  80. […] 比如,你有一个分类叫 “News”和另外一个分类叫 “Tutorials” ,你想要 “News” 分类下面的日志使用style1.css样式表, 而 “Tutorials”分类使用style2.css样式表. Lorelle 提供了一个简单的解决方案。参照下面的代码即可实现: […]

Post a Comment

Required fields are marked *
*
*