• Resolved dnbl00

    (@dnbl00)


    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)
  • (Check out this Pastebin so you can easily see the line numbers: https://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

    (@dnbl00)

    Thanks Stephen, I added in the closing brace on line 5 but it now saying:
    syntax error, unexpected ‘)’

    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

    (@dnbl00)

    That’s the complete error, it’s saying the error is on line 5

    Thread Starter dnbl00

    (@dnbl00)

    Here’s an updated pastebin: https://pastebin.com/Y4jMxu8V

    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

    (@dnbl00)

    Thanks cedcommerce, that works!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘T_ENDWHILE error’ is closed to new replies.