Title: PHP Conditionals
Last modified: August 18, 2016

---

# PHP Conditionals

 *  [Michael Benson](https://wordpress.org/support/users/michaelbenson/)
 * (@michaelbenson)
 * [19 years, 11 months ago](https://wordpress.org/support/topic/php-conditionals/)
 * Now, i am no PHP coding master. And i am struggling to quite comprehend where
   abouts i have gone wrong with the following code, which is trying to display 
   certain information when Category ID8 is being displayed, and another set of 
   information whenever any other category is being displayed.
 * `<?php if (is_category('8')) { ?>`
 * ### example code ###
 *  <?php } else { ?>
 * ### second example code ###
 * <?php } ?>
 * Currently only code from the else statement segment is being displayed. Even 
   though posts from Category ID8 are being extracted, they are treated as a post
   from Category ID2 for example.

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

 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [19 years, 11 months ago](https://wordpress.org/support/topic/php-conditionals/#post-405164)
 * is_category() doesn’t check what category the *post* is in. It checks to see 
   if you’re displaying a category archive page. In your case, it only returns true
   if the current page is the page with all the posts from category 8. Like [http://www.example.com/category/whateverCategory8sNameIs](http://www.example.com/category/whateverCategory8sNameIs).
 * If you want to check whether a post is in category 8 or not (while in The Loop),
   then you need to use in_category(‘8’) instead.
 *  Thread Starter [Michael Benson](https://wordpress.org/support/users/michaelbenson/)
 * (@michaelbenson)
 * [19 years, 11 months ago](https://wordpress.org/support/topic/php-conditionals/#post-405547)
 * Ah, thanks for your reply. I knew it must have been something to do with the 
   actual statement itself. Made your suggested fix and now works as intended. 🙂

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

The topic ‘PHP Conditionals’ is closed to new replies.

## Tags

 * [Coding](https://wordpress.org/support/topic-tag/coding/)
 * [conditional](https://wordpress.org/support/topic-tag/conditional/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [troubleshooting](https://wordpress.org/support/topic-tag/troubleshooting/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [Michael Benson](https://wordpress.org/support/users/michaelbenson/)
 * Last activity: [19 years, 11 months ago](https://wordpress.org/support/topic/php-conditionals/#post-405547)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
