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

---

# single.php and Categories

 *  [dbunit16](https://wordpress.org/support/users/dbunit16/)
 * (@dbunit16)
 * [17 years, 7 months ago](https://wordpress.org/support/topic/singlephp-and-categories/)
 * On my single.php page I want to have the tab of the article’s corresponding category
   highlighted.
 * For example: [http://embeddedcomputingsystems.com/](http://embeddedcomputingsystems.com/)
 * If the article is from “Boards” (the second tab next to “Home”) then I’d like
   the Boards tab to be in the active state. I’m am guessing I’d use some sort of
   php if statement, like if category=3 then class=”active” but am unsure of how
   to write this. I know nothing about php!
 * Can someone please help?
 * Thanks,
 * Jon

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

 *  Thread Starter [dbunit16](https://wordpress.org/support/users/dbunit16/)
 * (@dbunit16)
 * [17 years, 7 months ago](https://wordpress.org/support/topic/singlephp-and-categories/#post-884791)
 * I was able to find this code:
 *     ```
       <?php
       if (is_category(9)) {
          // looking for category 9 posts
          include(TEMPLATEPATH . '/single2.php');
       } else {
          // put this on every other category post
          include(TEMPLATEPATH . '/single1.php');
       }
       ?>
       ```
   
 * Can I just keep adding if statements? for each category before the else?
 *  Thread Starter [dbunit16](https://wordpress.org/support/users/dbunit16/)
 * (@dbunit16)
 * [17 years, 7 months ago](https://wordpress.org/support/topic/singlephp-and-categories/#post-884793)
 * In other words… is this valid:
 *     ```
       <?php
       if (is_category(1)) {
          // looking for category 1 posts
          include(TEMPLATEPATH . '/single1.php');
       if (is_category(9)) {
          // looking for category 2 posts
          include(TEMPLATEPATH . '/single2.php');
       if (is_category(9)) {
          // looking for category 3 posts
          include(TEMPLATEPATH . '/single3.php');
       if (is_category(9)) {
          // looking for category 4 posts
          include(TEMPLATEPATH . '/single4.php');
       } else {
          // put this on every other category post
          include(TEMPLATEPATH . '/single.php');
       }
       ?>
       ```
   
 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [17 years, 7 months ago](https://wordpress.org/support/topic/singlephp-and-categories/#post-884797)
 * Almost…
    if elseif elseif elseif else
 *  [iridiax](https://wordpress.org/support/users/iridiax/)
 * (@iridiax)
 * [17 years, 7 months ago](https://wordpress.org/support/topic/singlephp-and-categories/#post-884799)
 * > On my single.php page I want to have the tab of the article’s corresponding
   > category highlighted.
 * For posts, use in_category instead of is_category.
 *  Thread Starter [dbunit16](https://wordpress.org/support/users/dbunit16/)
 * (@dbunit16)
 * [17 years, 7 months ago](https://wordpress.org/support/topic/singlephp-and-categories/#post-884845)
 * Great! I will try this! Where would I place this code?
 *  Thread Starter [dbunit16](https://wordpress.org/support/users/dbunit16/)
 * (@dbunit16)
 * [17 years, 7 months ago](https://wordpress.org/support/topic/singlephp-and-categories/#post-884848)
 * I have tried the above code
 *     ```
       <?php
       if (is_category(11)) {
          // looking for category 11 posts
          include(TEMPLATEPATH . '/single11.php');
       elseif (is_category(9)) {
          // looking for category 2 posts
          include(TEMPLATEPATH . '/single2.php');
       elseif (is_category(9)) {
          // looking for category 3 posts
          include(TEMPLATEPATH . '/single3.php');
       elseif (is_category(9)) {
          // looking for category 4 posts
          include(TEMPLATEPATH . '/single4.php');
       } else {
          // put this on every other category post
          include(TEMPLATEPATH . '/singlegeneral.php');
       }
       ?>
       ```
   
 * But am getting this error “Parse error: parse error, unexpected T_ELSEIF in /
   home/content/a/z/e/azelasko/html/wp-content/themes/embedded411/single.php on 
   line 5”
 *  Thread Starter [dbunit16](https://wordpress.org/support/users/dbunit16/)
 * (@dbunit16)
 * [17 years, 7 months ago](https://wordpress.org/support/topic/singlephp-and-categories/#post-884850)
 * brackets weren’t closed! Thank you for your help!
 * iridiaz, that in_category was key! Thank you!
 *  [hamidelgendy](https://wordpress.org/support/users/hamidelgendy/)
 * (@hamidelgendy)
 * [17 years, 3 months ago](https://wordpress.org/support/topic/singlephp-and-categories/#post-884976)
 * That should be work fine
 *     ```
       <?php
       $post = $wp_query->post;
       if ( in_category('5') ) {
       include(TEMPLATEPATH . '/single2.php');
       }elseif ( in_category('3') ) {
       include(TEMPLATEPATH . '/single1.php');
       } else {
       include(TEMPLATEPATH . '/single.php');
       }
       ?>
       ```
   

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

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

## Tags

 * [active](https://wordpress.org/support/topic-tag/active/)
 * [categories](https://wordpress.org/support/topic-tag/categories/)
 * [single](https://wordpress.org/support/topic-tag/single/)
 * [single.php](https://wordpress.org/support/topic-tag/single-php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 8 replies
 * 4 participants
 * Last reply from: [hamidelgendy](https://wordpress.org/support/users/hamidelgendy/)
 * Last activity: [17 years, 3 months ago](https://wordpress.org/support/topic/singlephp-and-categories/#post-884976)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
