• 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

    (@keesiemeijer)

    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

    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

    (@upendra540)

    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.