WordPress.org

Ready to get started?Download WordPress

Forums

different single template depending on category (11 posts)

  1. stuboo
    Member
    Posted 8 years ago #

    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.

  2. Kafkaesqui

    Posted 8 years ago #

    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:

    http://wordpress.org/support/topic/27821#post-156289

    Read through the thread from there for directions on use.

  3. stuboo
    Member
    Posted 8 years ago #

    That looks smashing Kaf. I'll give it a try tonight when I get home from my real job. :(

  4. Michael Bishop

    Posted 8 years ago #

    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
    http://codex.wordpress.org/Template_Hierarchy

  5. moshu
    Member
    Posted 8 years ago #

    miklb,
    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.

  6. Michael Bishop

    Posted 8 years ago #

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

  7. Kafkaesqui

    Posted 8 years ago #

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

  8. Joni
    Member
    Posted 8 years ago #

    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:

    http://adaugeo.org

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

    http://zcar.org

    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.

  9. Kafkaesqui

    Posted 8 years ago #

    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.

  10. Kafkaesqui

    Posted 8 years ago #

    Post Templates by Category plugin *officially* released:
    http://wordpress.org/support/topic/39799

  11. Joni
    Member
    Posted 8 years ago #

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

    Signed,

    Happy girl in Houston.

Topic Closed

This topic has been closed to new replies.

About this Topic