Title: Problems with in_category()
Last modified: August 19, 2016

---

# Problems with in_category()

 *  Resolved [do77](https://wordpress.org/support/users/do77/)
 * (@do77)
 * [15 years ago](https://wordpress.org/support/topic/problems-with-in_category/)
 * Hi,
 * I want to style single posts of category 1 different than those of category 2.
   In the function reference I read that this can be achieved with in_category()
   so I added the tag to my single.php file within the loop. However, now it says
   I have an unexpected error ‘<‘ on line 36.
 * Here is my code:
 *     ```
       <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
   
       <?php if ( in_category( 'news' )) {
   
       <h1><?php the_title(); ?></h1>
       <div class="single"><?php the_content(__('Read more', ''));?></div>
   
       } else {
   
       <h1><?php the_title(); ?></h1>
       <div>A lot of code including custom fields and an if statement if a user is logged in etc. </div>
   
       }
       ?>
       ```
   
 * Any idea what I am doing wrong? Would appreciate your help!

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years ago](https://wordpress.org/support/topic/problems-with-in_category/#post-2038581)
 * make sure to close and open your php tags anytime the code switches to and from
   html code:
 *     ```
       <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
   
       <?php if ( in_category( 'news' )) { ?>
   
       <h1><?php the_title(); ?></h1>
       <div class="single"><?php the_content(__('Read more', ''));?></div>
   
       <?php } else { ?>
   
       <h1><?php the_title(); ?></h1>
       <div>A lot of code including custom fields and an if statement if a user is logged in etc. </div>
   
       <?php }
       ?>
       ```
   
 *  Thread Starter [do77](https://wordpress.org/support/users/do77/)
 * (@do77)
 * [15 years ago](https://wordpress.org/support/topic/problems-with-in_category/#post-2038634)
 * That was it! Thank you so much alchymyth!

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

The topic ‘Problems with in_category()’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [do77](https://wordpress.org/support/users/do77/)
 * Last activity: [15 years ago](https://wordpress.org/support/topic/problems-with-in_category/#post-2038634)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
