Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

WordPress WordPress Theme Development The WordPress Loop Adding the Loop to the index.php File

melissa brown
melissa brown
4,670 Points

error msg

all working fine until I tried to add a static front page and then I got this error msg? Parse error: syntax error, unexpected 'endwhile' (T_ENDWHILE) in C:\xampp\htdocs\localwp.com\wp-content\themes\th_practice theme\page.php on line 22

Now I cant even get back into wordpress admin area through local host. I don’t understand why it did this because I didn’t change the code?

<?php get_header(); ?>

<section class="row">
  <div class="small-12 columns text-center">
    <div class="leader">

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

      <h1><?php the_title(); ?></h1>
      <p><?php the_content(); ?></p>        

  <?php endwhile; else : ?>

    <p><?php _e( 'Sorry, no results found.', 'treehouse-portfolio' ); ?></p>

  <?php endif; ?>

    </div>
  </div>
</section>

<?php get_footer(); ?>

Hi Melissa,

You are missing an endwhile; and endif;. Try this instead:

<div class="leader">

<?php if ( have_posts() ) : ?>

    <?php while ( have_posts() ) : the_post(); ?>

      <h1><?php the_title(); ?></h1>
      <p><?php the_content(); ?></p>        

    <?php endwhile; ?>

<?php else: ?>

    <p><?php _e( 'Sorry, no results found.', 'treehouse-portfolio' ); ?></p>

<?php endif; ?>

</div>

1 Answer

melissa brown
melissa brown
4,670 Points

actually i have the end while end if, not sure why it didnt post when i posted my code. my end while end else was like this i changed it to the one you suggested but nothing changed.

  <?php endwhile; else : ?>
<?php get_header(); ?>

<section class="row">
  <div class="small-12 columns text-center">
    <div class="leader">

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

      <h1><?php the_title(); ?></h1>
      <p><?php the_content(); ?></p>        

<?php endwhile; ?>

<?php else: ?>

    <p><?php _e( 'Sorry, no results found.', 'treehouse-portfolio' ); ?></p>

  <?php endif; ?>

    </div>
  </div>
</section>

<?php get_footer(); ?>