Title: Need help with PHP code
Last modified: August 18, 2016

---

# Need help with PHP code

 *  Resolved [Storyman](https://wordpress.org/support/users/storyman/)
 * (@storyman)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/need-help-with-php-code-1/)
 * There are 6 different main categories and a couple of dozen sub-categories for
   each main category. So, creating a ‘category-#.php’ page for all of the sub-category
   pages kills the idea of a dynamic site.
 * What I need is to test against the 6 main categories (IDs 1-6). Each main category
   has its own sidebar (sidebar1.php … sidebar6.php).
 * Being somewhat new to WordPress and PHP, I don’t know how to test for a particular
   category.
 * If you could provide a sample of how to set up the condition it would be greatly
   appreciated.
 * Thanks

Viewing 1 replies (of 1 total)

 *  Thread Starter [Storyman](https://wordpress.org/support/users/storyman/)
 * (@storyman)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/need-help-with-php-code-1/#post-636932)
 * Thanks to an earlier post by tptboy, I was able to piece this together. After
   getting the parent ID# for the parent it is used to select the sidebar file. 
   There is a corresponding sidebar # for each category.
 * Is any of the code I used deprecated?
 * $cat_object = $wp_query->get_queried_object();
    $cat_parent = $cat_object->category_parent;
   include (‘sidebar’.$cat_parent.’.php’);

Viewing 1 replies (of 1 total)

The topic ‘Need help with PHP code’ is closed to new replies.

 * 1 reply
 * 1 participant
 * Last reply from: [Storyman](https://wordpress.org/support/users/storyman/)
 * Last activity: [18 years, 8 months ago](https://wordpress.org/support/topic/need-help-with-php-code-1/#post-636932)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
