• 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.

Viewing 6 replies - 1 through 6 (of 6 total)
  • 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).

    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. https://codex.www.ads-software.com/Template_Tags/in_category

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

    Thread Starter Levant Technologies

    (@hobbahobba)

    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.

    Did you look at the plugin I linked yet?

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    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';
    }
    ?>
    Thread Starter Levant Technologies

    (@hobbahobba)

    Did you look at the plugin I linked yet?

    Working great. Thanks ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Is it possible to have multiple templates for SINGLE posts?’ is closed to new replies.