Forums

Use a specific single.php template for specific categories (7 posts)

  1. chris2006
    Member
    Posted 3 years ago #

    Hi,

    When creating a new post and assigning it to a specific category (say, video) i would like the post to be displayed using a specific (video)single.php template.

    Does anyone know the code to make this work?

    i have 4 categories i would like to do this with.

    When selected:

    cat1 or cat 2 = newssingle.php
    cat3 or cat 4 = videosingle.php

    Any help would be fantastic!

    Thankyou.

  2. Otto
    Tech Ninja
    Posted 3 years ago #

    if (in_category(1) || in_category(2)) include 'newsingle.php';
    else if (in_category(3) || in_category(4)) include 'videosingle.php';
  3. chris2006
    Member
    Posted 3 years ago #

    Thats great thanks!

    Do i add this to the index.php template in the loop?

  4. Otto
    Tech Ninja
    Posted 3 years ago #

    You'd probably want to put that in the single.php file.

  5. gmisen
    Member
    Posted 3 years ago #

    did this work for you? i'm having the same problem, but so far i haven't put that code in a place that doesn't make my page go wacky.
    where in the single.php file did you put it?

  6. krusch
    Member
    Posted 3 years ago #

    I would like to link to a different single.php from my archive page.

    Let's say home.php links to single.php
    and archive.php links to single_x.php

    Any ideas?

    Felix

    //---> I just opened a new question for this!

    http://wordpress.org/support/topic/24125

  7. gmisen
    Member
    Posted 3 years ago #

    ok i used this but it looks like its putting one template on top of the other. single_x displays properly but i want it to display INSTEAD of single.php not alongside it. should i use another word besides 'include'?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.