Title: Parse error: syntax error, unexpected &#039;endwhile&#039; (T_ENDWHILE)
Last modified: August 31, 2016

---

# Parse error: syntax error, unexpected 'endwhile' (T_ENDWHILE)

 *  [Upendra540](https://wordpress.org/support/users/upendra540/)
 * (@upendra540)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/parse-error-syntax-error-unexpected-endwhile-t_endwhile-3/)
 * hey,
 * I’m trying to add more than one page to my wordpress site.
 * After putting in some test text, publishing and trying to view the page it gives
   me this error.
 * Parse error: syntax error, unexpected ‘endwhile’ (T_ENDWHILE)
 * you can check out my code
 *     ```
       <?php
       get_header();
       ?>
   
           <!-- Page Head -->
           <?php get_template_part("banners/default_page_banner"); ?>
   
           <!-- Content -->
           <div class="container contents single">
               <div class="row">
                   <div class="span9 main-wrap">
                       <!-- Main Content -->
                       <div class="main">
   
                           <div class="inner-wrapper">
   
                                               if ( has_post_thumbnail() )
                                               {
                                                   $image_id = get_post_thumbnail_id();
                                                   $image_url = wp_get_attachment_url($image_id);
                                                   echo '<a href="'.$image_url.'" title="'.get_the_title().'">';
                                                   the_post_thumbnail('post-featured-image');
                                                   echo '</a>';
                                               }
   
                                               the_content();
   
                                               // WordPress Link Pages
                                               wp_link_pages(array('before' => '<div class="pages-nav clearfix">', 'after' => '</div>', 'next_or_number' => 'next'));
                                               ?>
                                       </article>
                                       <?php
                                   endwhile;
                                   comments_template();
                                   endif;
                               ?>
                           </div>
   
                       </div><!-- End Main Content -->
   
                   </div> <!-- End span9 -->
   
                   <?php get_sidebar('pages'); ?>
   
               </div><!-- End contents row -->
   
           </div><!-- End Content -->
   
       <?php get_footer(); ?>
       ```
   
 * Please find a solution for me
 * thanks,

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

 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/parse-error-syntax-error-unexpected-endwhile-t_endwhile-3/#post-6923963)
 * It seems you’re missing this part from the loop
 *     ```
       <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
       ```
   
 * [https://codex.wordpress.org/The_Loop](https://codex.wordpress.org/The_Loop)
 * I think it should go after this:
 *     ```
       <div class="inner-wrapper">
       ```
   
 * Try it with this
 *     ```
       <?php
       get_header();
       ?>
   
           <!-- Page Head -->
           <?php get_template_part("banners/default_page_banner"); ?>
   
           <!-- Content -->
           <div class="container contents single">
               <div class="row">
                   <div class="span9 main-wrap">
                       <!-- Main Content -->
                       <div class="main">
   
                           <div class="inner-wrapper">
                               <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
                                       <article>
                                           <?php if ( has_post_thumbnail() )
                                               {
                                                   $image_id = get_post_thumbnail_id();
                                                   $image_url = wp_get_attachment_url($image_id);
                                                   echo '<a href="'.$image_url.'" title="'.get_the_title().'">';
                                                   the_post_thumbnail('post-featured-image');
                                                   echo '</a>';
                                               }
   
                                               the_content();
   
                                               // WordPress Link Pages
                                               wp_link_pages(array('before' => '<div class="pages-nav clearfix">', 'after' => '</div>', 'next_or_number' => 'next'));
                                               ?>
                                       </article>
                                       <?php
                                   endwhile;
                                   comments_template();
                                   endif;
                               ?>
                           </div>
   
                       </div><!-- End Main Content -->
   
                   </div> <!-- End span9 -->
   
                   <?php get_sidebar('pages'); ?>
   
               </div><!-- End contents row -->
   
           </div><!-- End Content -->
   
       <?php get_footer(); ?>
       ```
   
 * What theme template is this?
 *  Thread Starter [Upendra540](https://wordpress.org/support/users/upendra540/)
 * (@upendra540)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/parse-error-syntax-error-unexpected-endwhile-t_endwhile-3/#post-6924054)
 * Well the code which you have given worked like a charm, it’s my own code which
   i’ve written i’m so thankfull for your help. 🙂

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

The topic ‘Parse error: syntax error, unexpected 'endwhile' (T_ENDWHILE)’ is closed
to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [Upendra540](https://wordpress.org/support/users/upendra540/)
 * Last activity: [10 years, 2 months ago](https://wordpress.org/support/topic/parse-error-syntax-error-unexpected-endwhile-t_endwhile-3/#post-6924054)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
