Title: if in_category code question
Last modified: August 19, 2016

---

# if in_category code question

 *  Resolved [csleh](https://wordpress.org/support/users/csleh/)
 * (@csleh)
 * [17 years, 10 months ago](https://wordpress.org/support/topic/if-in_category-code-question/)
 * Can anything be added to this code
 *     ```
       <?php if (in_category('3')) : ?>
       <p class="date">POSTED <?php the_time('F d, Y') ?></p>
       <?php endif; ?>
       ```
   
 * that will say “if in category 3 EXCEPT for post 50, show this”
 * I tried
    `<?php if (in_category('3&exclude=50')) : ?> and (in_category('3&exclude
   =p50'))` but that deletes the code on all the posts

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

 *  [iridiax](https://wordpress.org/support/users/iridiax/)
 * (@iridiax)
 * [17 years, 10 months ago](https://wordpress.org/support/topic/if-in_category-code-question/#post-801769)
 * The only parameter you can use is the category ID:
 * [http://codex.wordpress.org/Template_Tags/in_category](http://codex.wordpress.org/Template_Tags/in_category)
 *  Thread Starter [csleh](https://wordpress.org/support/users/csleh/)
 * (@csleh)
 * [17 years, 10 months ago](https://wordpress.org/support/topic/if-in_category-code-question/#post-801784)
 * Right, that’s what I understood the code to be.
 * Here’s the goal:
    category 3 is news. Everything in news should look the same,
   generally. There is one post (50) that is info for media. The site uses breadcrumbs,
   so you can see the path on the page. If you are looking at a press release (99%
   of news category items), you should see the date posted. But if you are looking
   at the media info page, the posting date doesn’t make sense.
 * There could be a second category that only has the media info, but that would
   be confusing — not only do I have to pull in an additional category whenever 
   referencing news, but viewers would see a different path in the breadcrumbs.
 * My thought was that if I could just exclude one post from the in_category call
   all these problems would be fixed. I am open to any suggestions?
 *  Thread Starter [csleh](https://wordpress.org/support/users/csleh/)
 * (@csleh)
 * [17 years, 10 months ago](https://wordpress.org/support/topic/if-in_category-code-question/#post-801880)
 * I’m sure there is a cleaner way, but adding another if-else inside the first 
   one (for category) to test for a single post with ID of 50 (the media sheet) 
   did the trick.
 *     ```
       <?php if (in_category('3')) : ?>
       <?php if( is_single(50) ) : ?>
       <?php else : ?>
       <p class="newsdatepage">TROY, MICHIGAN &mdash; <?php the_time('F d, Y') ?>
   
       <?php endif; ?>
       <?php endif; ?>
       ```
   
 *  [VelvetBlues.com](https://wordpress.org/support/users/velvetbluescom/)
 * (@velvetbluescom)
 * [17 years, 10 months ago](https://wordpress.org/support/topic/if-in_category-code-question/#post-801881)
 * Cleaner way:
 *     ```
       <?php if (in_category('3') && !is_single(50)) : ?>
       <p class="newsdatepage">TROY, MICHIGAN &mdash; <?php the_time('F d, Y') ?>
       <?php endif; ?>
       ```
   
 *  Thread Starter [csleh](https://wordpress.org/support/users/csleh/)
 * (@csleh)
 * [17 years, 10 months ago](https://wordpress.org/support/topic/if-in_category-code-question/#post-801882)
 * OK, so the `"&&` is saying “if this is also true” and the `!` is saying “leave
   this one out”. Is that right?

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

The topic ‘if in_category code question’ is closed to new replies.

## Tags

 * [code](https://wordpress.org/support/topic-tag/code/)
 * [in_category](https://wordpress.org/support/topic-tag/in_category/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 3 participants
 * Last reply from: [csleh](https://wordpress.org/support/users/csleh/)
 * Last activity: [17 years, 10 months ago](https://wordpress.org/support/topic/if-in_category-code-question/#post-801882)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
