Title: Category and single.php
Last modified: August 19, 2016

---

# Category and single.php

 *  [matata](https://wordpress.org/support/users/matata/)
 * (@matata)
 * [17 years, 5 months ago](https://wordpress.org/support/topic/category-and-singlephp/)
 * Hey, a category I want to publish under a different template than the topic single.
   php. Just as it works for sites that you can create your draft, as well as post?
   For example, the category of the dog -> single.php and category cat -> single2.
   php Is it a trick or plugin? Excuse my poor English. I hope that you understand.
   Thank you for any advice.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Samuel B](https://wordpress.org/support/users/samboll/)
 * (@samboll)
 * [17 years, 5 months ago](https://wordpress.org/support/topic/category-and-singlephp/#post-932283)
 * [http://codex.wordpress.org/Category_Templates](http://codex.wordpress.org/Category_Templates)
 *  [SimonJ](https://wordpress.org/support/users/simonj/)
 * (@simonj)
 * [17 years, 5 months ago](https://wordpress.org/support/topic/category-and-singlephp/#post-932297)
 * Hi Matata
 * To do so, I use the “single.php” file as a “switch”.
 * You need to use the “conditional tags” :
    [http://codex.wordpress.org/Conditional_Tags](http://codex.wordpress.org/Conditional_Tags)
 * —-
 * Let’s see with an example.
 * As you wrote, imagine you have :
 * category Id 2 : DOG
 * Then you need :
 * **1 – single.php **: you will use this a a swith
 * **2 – single_dog.php** : the template you want for the post in the dog category
 * **3 – single_normal.php** : the template you want in any other category.
 * in your single.php file, you just write the conditions like this :
 *     ```
       <?php
       if (in_category('2')) {include (TEMPLATEPATH . '/single_dog.php');
       }
       else { include (TEMPLATEPATH . '/single_normal.php');
       }
       ?>
       ```
   
 * In english, it tells to wordpress : if the post is in catagory 2 (dog), open 
   the single_dog.php template file … If the post is in any other category, open
   the single_normal.php template file.
 * You don’t need anything else in your single.php. It’s simply a switch. Then, 
   you create two different template file in single_dog.php and in single_normal.
   php, just as you would do in the standart single.php.
 * Of course, you can do this for other categories… Let’s say you want a template
   for posts in the category “dog” (id 2) and another for posts in the category “
   cat” (id 3)
 * Then, you will use the “elseif” condition :
 *     ```
       <?php
       if (in_category('2')) {include (TEMPLATEPATH . '/single_dog.php');
       }
       elseif  (in_category('3')) {include (TEMPLATEPATH . '/single_cat.php');
       }
       else { include (TEMPLATEPATH . '/single_normal.php');
       }
       ?>
       ```
   
 * Of course, you adjust this code to fit your own needs… You can use this method
   for any category you want. There is no limit for the amount of “elseif” condition…
   You can also group a condition for several categories :
 *     ```
       elseif (in_category('8') || in_category (9)){include (TEMPLATEPATH . '/single_example.php');
       ```
   
 * Single_example.php will then be used if the post is in catagory 8 or in category
   9…
 * Good luck.
 * S.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Category and single.php’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 3 participants
 * Last reply from: [SimonJ](https://wordpress.org/support/users/simonj/)
 * Last activity: [17 years, 5 months ago](https://wordpress.org/support/topic/category-and-singlephp/#post-932297)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
