WordPress.org

Ready to get started?Download WordPress

Forums

Is it possible to have multiple templates for SINGLE posts? (7 posts)

  1. hobbahobba
    Member
    Posted 6 years ago #

    I have posts with category "cars", "vehicles", "bikes" and want them to have separate SINGLE templates based on their category.

    - "cars" single posts will have blue background colors.
    - "vehicles" single posts will have red background colors.
    - "bikes" single posts will have green background colors.

    Is there a way to do that (separation)? Please help.

  2. Chris_K
    Member
    Posted 6 years ago #

    Try the Post Templates by Category plugin. I think it'll do what you're after.

    As for displaying a list of posts within a category you may want to dabble with Category_Templates (if you haven't already, that is).

  3. Roger Theriault
    Member
    Posted 6 years ago #

    If all you need is a changeup of color, if you stick the category into the class of a wrapper div you can create CSS rules to set colors (and background images and overall look and feel if you want). If you're not really changing the page structure, try CSS first.

    eg:

    single.php

    <div id="theme-wrapper" class="<?php the_category(' '); ?>">
    ...
    <h2>A big ol Buick</h2>
    ...
    </div>

    style.css

    /* colors */
    #theme-wrapper.cars h2 {
       background-color: blue;
    }
    #theme-wrapper.vehicles h2 {
       background-color: red;
    }
    #theme-wrapper.bikes h2 {
       background-color: green;
    }

    If that's not what you need, you can use conditional tags in your single.php to make minor changes without having to worry about keeping three files in relative sync. http://codex.wordpress.org/Template_Tags/in_category

    (There are plenty of features in WordPress to accomplish things without adding too much complexity.)

  4. hobbahobba
    Member
    Posted 6 years ago #

    I already have the category template issue figured out. But having separate templates for single posts off those categories are the main problem, and it's beyond just changing color. Each template will have completely different layout, images and feel to it.

  5. Chris_K
    Member
    Posted 6 years ago #

    Did you look at the plugin I linked yet?

  6. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    Something like this in single.php:

    <?php
    if ( have_posts() ) { the_post(); rewind_posts(); }
    if (in_category(1)) {
    include 'single_cars.php';
    }
    else if (in_category(2)) {
    include 'single_bikes.php';
    }
    else if (in_category(3)) {
    include 'single_vehicles.php';
    }
    ?>
  7. hobbahobba
    Member
    Posted 6 years ago #

    Did you look at the plugin I linked yet?

    Working great. Thanks :)

Topic Closed

This topic has been closed to new replies.

About this Topic