Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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(); ?>