Support » Themes and Templates » different single template depending on category

  • Hello all. I’m a MT convert and am having some difficulty making the mental transition regarding templates. I did a search but since there are no real keywords for my problem I wasn’t able to find anything.

    My layout calls for posts in the ‘photo’ category to use a different template than posts in a regular category (i.e. text based posts). What do I need to do to create the logic that says, “This post is in the ‘photo’ category therefore the single post template needs to be the one that’s associated with photos”

    I hope this makes some sense. Please feel free to ask for clarification.

    Thanks in advance.

Viewing 10 replies - 1 through 10 (of 10 total)
  • There’s a few PHP-scriptish ways to do this (and I’m sure someone will be by soon to point to them), but here’s a plugin of mine that accomplishes what you’re after:

    Read through the thread from there for directions on use.

    That looks smashing Kaf. I’ll give it a try tonight when I get home from my real job. 🙁

    Another simple method is simply to create th template, and then call it category-5.php, or whatever the cat ID is for photos. The template hierarchy looks for a cat specific template first, then a cat, etc

    I am afraid the OP was asking how to have a different template for single posts in a certain category. Your example (category-5.php) doesn’t work when single posts are viewed, only with category listings. At least this is how I understand it based on the Template Hierarchy and Category Templates in Codex.

    Ah, I both misread the OP, and misunderstood the hierarchy myself.

    Using category-5.php as a template for posts in that category *will* work in conjunction with the plugin.

    Kafkaesqui, I am wondering if your plugin will work for what I’m trying to accomplish with my car club site.

    Right now, I’m using a category-specific page for the President’s Message. At the bottom of that page, I have her signature GIF file. What I wanted to do with that page is when a new President’s Message is posted (there is one each month), it is displayed on the front page. It’s no big deal if we can’t get the sig. GIF to appear there without just cutting and pasting it (President is kinda computer-challenged if you know what I mean). But when the user clicks on an archive link or category link or the permalink to the message, we want the page to have the sig. GIF at the bottom of the LATEST entry and either excerpts or a link list below that of previous month’s messages.

    I’ve kinda of got something cobbled together for it, but it displays the entire message — all of them — on the category page.

    Any suggestions for another way to handle would be appreciated.

    The TESTBED is here:

    The live (previous) version of our current site is here:

    Right now, we are using Blogger to create the President’s message and it never appears on the front page, just on a linked page.

    Joni, as I understand your question yes, you could do something like that with the plugin (which I’m updating and writing up on my blog as I compose this — well, before and after composing this).

    The plugin lets you choose if posts in a category inherit the category template (category-5.php) or use a template for posts in a category (single-cat-5.php). With the latter method you can create a template for posts in the “President’s Message” category that incorporates the signature gif, removes the comments_template() tag, and varies from other posts in any way you’d like.

    Post Templates by Category plugin *officially* released:

    Kafka, you better update your PayPal link while you’re at it, because I’m fixing to hit that too. You are absolutely awesome!!!


    Happy girl in Houston.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘different single template depending on category’ is closed to new replies.