• Hi there. I am creating my first ever basic theme to get to used to coding and creating themes for WordPress but I have hit some syntax errors and would love some help / guidance. I am having problems with “<?php endwhile; ?>” and “<?php else : ?>”

    Testing local error

    Parse error: syntax error, unexpected ‘endwhile’ (T_ENDWHILE) in C:\xampp\htdocs\wordpress\wp-content\themes\danielwaddon\index.php on line 13

    <?php get_header(); ?>
    <?php if (have_posts()) ; ?>
    <?php while (have_posts()) ; the_post(); ?>
    <article <?php post_class() ?> id='post-<?php the_ID(); ?>">
    	<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        posted on: <?php echo get_the_date(); ?> at <?php echo get_the_time(); ?>
        Posted in: <?php the_category(','); ?>
    
    <?php the_content('Read More..'); ?>
    posted by: <?php the_author(); ?> | <?php comments_popup_link('No Comments','1 Comments','% Comments'); ?>
    </article>
    
    <?php endwhile; ?>
    <?php next_post_link('&laquo; Previous Entries') ?>
    <?php previous_post_link('Next Entries &raquo;') ?>
    <?php else : ?>
    <p>Not Found</p>
    <p>Sorry, but you are looking for something that isn't here.</p>
    <?php endif; ?>
    </section>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
Viewing 7 replies - 1 through 7 (of 7 total)
  • You’ve got the wrong syntax for your if and while statements. You need to have colons and not semicolons afterwards:

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

    (@danielwaddon)

    Thanks stephencottontail

    I am now getting another local testing error

    Fatal error: Call to undefined function get_header() in C:\xampp\htdocs\wordpress\wp-content\themes\danielwaddon\index.php on line 1

    The new code

    <?php get_header(); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <article <?php post_class() ?> id='post-<?php the_ID(); ?>">
    	<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        posted on: <?php echo get_the_date(); ?> at <?php echo get_the_time(); ?>
        Posted in: <?php the_category(','); ?>
    
    <?php the_content('Read More..'); ?>
    posted by: <?php the_author(); ?> | <?php comments_popup_link('No Comments','1 Comments','% Comments'); ?>
    </article>
    
    <?php endwhile; ?>
    <?php next_post_link('&laquo; Previous Entries') ?>
    <?php previous_post_link('Next Entries &raquo;') ?>
    <?php else : ?>
    <p>Not Found</p>
    <p>Sorry, but you are looking for something that isn't here.</p>
    <?php endif; ?>
    </section>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    How are you trying to load your theme? Are you attempting to directly access index.php (i.e., are you pointing an <a> tag directly at /path/to/index.php)?

    Thread Starter danielwaddon

    (@danielwaddon)

    if I am getting your question correctly then I am calling it via the index.php page

    <?php get_header(); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <article <?php post_class() ?> id='post-<?php the_ID(); ?>">
    	<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        posted on: <?php echo get_the_date(); ?> at <?php echo get_the_time(); ?>
        Posted in: <?php the_category(','); ?>
    
    <?php the_content('Read More..'); ?>
    posted by: <?php the_author(); ?> | <?php comments_popup_link('No Comments','1 Comments','% Comments'); ?>
    </article>
    
    <?php endwhile; ?>
    <?php next_post_link('&laquo; Previous Entries') ?>
    <?php previous_post_link('Next Entries &raquo;') ?>
    <?php else : ?>
    <p>Not Found</p>
    <p>Sorry, but you are looking for something that isn't here.</p>
    <?php endif; ?>
    </section>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    Thanks your information.

    Thread Starter danielwaddon

    (@danielwaddon)

    Sorry mayraharpermr. I am not sure what you are trying to say or ask for that matter.

    What do you have set for “WordPress Address (URL)” and “Site Address (URL)” under Dashboard > Settings > General? Are you trying to access index.php directly, i.e., by going to http://localhost/index.php?

    Also, can you post the contents of header.php?

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