Title: Wp queries for single.php template
Last modified: August 31, 2016

---

# Wp queries for single.php template

 *  Resolved [frusi](https://wordpress.org/support/users/frusi/)
 * (@frusi)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/wp-queries-for-singlephp-template/)
 * Hey guys,
 * I am using the following code for the single post:
 *     ```
       <?php
         $post = $wp_query->post;
         if (in_category('portfolio')) {
             include(TEMPLATEPATH.'/single_portfolio.php');
         } elseif (in_category('news')) {
             include(TEMPLATEPATH.'/single_news.php');
         } elseif(has_tag('review') && in_category('news')){
             include(TEMPLATEPATH.'/single_review.php');
         }
         else{
             include(TEMPLATEPATH.'/single_default.php');
         }
       ?>
       ```
   
 * However, for the single_review I am checking if it’s inside category news and
   has tag “review”, but it’s not working. Any suggestions? Thank you.

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/wp-queries-for-singlephp-template/#post-7024284)
 * what is ‘not working’?
 * from the sequence of your conditional statements, anything in the category ‘news’
   will get the template ‘/single_news.php’ –
 * rewrite the code, going from the specific to the general ….
 *  Thread Starter [frusi](https://wordpress.org/support/users/frusi/)
 * (@frusi)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/wp-queries-for-singlephp-template/#post-7024319)
 * [@micheal](https://wordpress.org/support/users/micheal/) thank you so much. You
   were right, it was enough to swap the order of the condition, I guess my brain
   was frying. For anyone else who might need this. Here s the working code.
 * <?php
    $post = $wp_query->post; if (in_category(‘portfolio’)) { include(TEMPLATEPATH.’/
   single_portfolio.php’); } elseif(has_tag(‘review’) && in_category(‘news’)){ include(
   TEMPLATEPATH.’/single_review.php’); } elseif (in_category(‘news’)) { include(
   TEMPLATEPATH.’/single_news.php’); } else{ include(TEMPLATEPATH.’/single_default.
   php’); } ?>

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

The topic ‘Wp queries for single.php template’ is closed to new replies.

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [tag](https://wordpress.org/support/topic-tag/tag/)
 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [frusi](https://wordpress.org/support/users/frusi/)
 * Last activity: [10 years, 3 months ago](https://wordpress.org/support/topic/wp-queries-for-singlephp-template/#post-7024319)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
