Title: Post template based on categories
Last modified: August 21, 2016

---

# Post template based on categories

 *  [inrajaka](https://wordpress.org/support/users/inrajaka/)
 * (@inrajaka)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/post-template-based-on-categories/)
 * I have successfully
 * 1. Created a page displaying posts on a category
    2. Created a custom field to
   display menu based on that page
 * But when I click on a post of that category, the menu comes back to the default
   one.
 * What I try to achieve is, all posts in that category and subcategories will show
   the menu that I designed for the category and subs. Should I use conditional 
   tags or something?
 * Any help is appreciated…

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

 *  Thread Starter [inrajaka](https://wordpress.org/support/users/inrajaka/)
 * (@inrajaka)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/post-template-based-on-categories/#post-4095682)
 * Is there anyone around?
 *  [vjpo](https://wordpress.org/support/users/vjpo/)
 * (@vjpo)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/post-template-based-on-categories/#post-4095700)
 * Yes, conditional tag [in_category()](http://codex.wordpress.org/Function_Reference/in_category)
   is a variant to use.
 *  Thread Starter [inrajaka](https://wordpress.org/support/users/inrajaka/)
 * (@inrajaka)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/post-template-based-on-categories/#post-4095716)
 * Thanks… I will try that. Is there any way to declare the category and its subcategories?
   Adding numbers is hard
 *  [vjpo](https://wordpress.org/support/users/vjpo/)
 * (@vjpo)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/post-template-based-on-categories/#post-4095755)
 *     ```
       $special_cats[] = 1; // 1 is ID of parent cat
       $args = array(
           'child_of' => $special_cats[0];
       );
       $categories = get_categories($args);
       foreach($categories as $category) {
           $special_cats[] = $category->cat_ID;
       }
       (in_category($special_cats) || is_category($special_cats)) ? $theme_location = 'special' : $theme_location = 'default';
       wp_nav_menu(array(
           'theme_location' => $theme_location
       ));
       ```
   
 * Example

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

The topic ‘Post template based on categories’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [vjpo](https://wordpress.org/support/users/vjpo/)
 * Last activity: [12 years, 8 months ago](https://wordpress.org/support/topic/post-template-based-on-categories/#post-4095755)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
