Title: T_ENDWHILE error
Last modified: September 1, 2016

---

# T_ENDWHILE error

 *  Resolved [dnbl00](https://wordpress.org/support/users/dnbl00/)
 * (@dnbl00)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/t_endwhile-error/)
 * Hi there, i’m getting a
    **Parse error: syntax error, unexpected ‘endwhile’ (
   T_ENDWHILE)**
 * This is whats causing it to break
 *     ```
       <div class="carousel-inner" role="listbox">
   
       	      <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); $i++; ?>
   
       	      <?php if ($i==1) { ?>
               <div class="item active">
       	       <?php } else { ?>
       	       <div class="item">
       		       <?php if ( has_post_thumbnail ()) {
       			       $url = wp_get_attachment_url( get_post_thumbnail_id());
       			       ?>
                 <img src="<?php echo $url; ?>" alt="<?php the_title(); ?>">
                 <?php } ?>
                 <div class="container">
                   <div class="carousel-caption">
                     <h1><?php the_title(); ?></h1>
                     <p><a class="btn btn-lg btn-primary" href="<?php the_permalink(); ?>" role="button">Read more</a></p>
                   </div>
                 </div>
               </div>
               <?php endwhile; endif; ?>
       ```
   
 * Any help would be appreciated!

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

 *  [stephencottontail](https://wordpress.org/support/users/stephencottontail/)
 * (@stephencottontail)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/t_endwhile-error/#post-7567770)
 * (Check out this Pastebin so you can easily see the line numbers: [http://pastebin.com/1wR5uy5e](http://pastebin.com/1wR5uy5e))
 * What’s likely happening here is that you’ve forgotten the closing brace for the
   if-block opened on line 5 (`if ($1 == 1)`). It looks like the closing brace on
   line 13 is correctly matched with the if-block opened on line 9, and then there’s
   nothing to close the if-block on line 5, so the parser sees the `endwhile` and
   gets confused.
 *  Thread Starter [dnbl00](https://wordpress.org/support/users/dnbl00/)
 * (@dnbl00)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/t_endwhile-error/#post-7567772)
 * Thanks Stephen, I added in the closing brace on line 5 but it now saying:
    **
   syntax error, unexpected ‘)’**
 *  [stephencottontail](https://wordpress.org/support/users/stephencottontail/)
 * (@stephencottontail)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/t_endwhile-error/#post-7567774)
 * What is your current code? Also, is that the complete error? Usually PHP will
   tell you the line number where the error occurred.
 *  Thread Starter [dnbl00](https://wordpress.org/support/users/dnbl00/)
 * (@dnbl00)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/t_endwhile-error/#post-7567775)
 * That’s the complete error, it’s saying the error is on line 5
 *  Thread Starter [dnbl00](https://wordpress.org/support/users/dnbl00/)
 * (@dnbl00)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/t_endwhile-error/#post-7567776)
 * Here’s an updated pastebin: [http://pastebin.com/Y4jMxu8V](http://pastebin.com/Y4jMxu8V)
 *  [cedcommerce](https://wordpress.org/support/users/cedcommerce/)
 * (@cedcommerce)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/t_endwhile-error/#post-7567778)
 * Hello dnbl00,
    You have not closed if condition in the code. Use following code:
 *     ```
       <div class="carousel-inner" role="listbox">
   
        <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); $i++; ?>
   
          <?php if ($i==1) { ?>
           <div class="item active">
             <?php } else { ?>
                <div class="item">
                <?php if ( has_post_thumbnail ()) {
                 $url = wp_get_attachment_url( get_post_thumbnail_id());
                 ?>
                 <img src="<?php echo $url; ?>" alt="<?php the_title(); ?>">
                 <?php } ?>
                 <div class="container">
                   <div class="carousel-caption">
                     <h1><?php the_title(); ?></h1>
                     <p><a class="btn btn-lg btn-primary" href="<?php the_permalink(); ?>" role="button">Read more</a></p>
                   </div>
                 </div>
               </div>
               <?php }?>
             <?php endwhile; endif; ?>
       ```
   
 *  Thread Starter [dnbl00](https://wordpress.org/support/users/dnbl00/)
 * (@dnbl00)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/t_endwhile-error/#post-7567779)
 * Thanks cedcommerce, that works!

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

The topic ‘T_ENDWHILE error’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 7 replies
 * 3 participants
 * Last reply from: [dnbl00](https://wordpress.org/support/users/dnbl00/)
 * Last activity: [9 years, 10 months ago](https://wordpress.org/support/topic/t_endwhile-error/#post-7567779)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
