For a homepage template I'm trying to query a custom post type with a couple custom meta boxes. They are a title, oembed text field, and text area. I've compiled the below code from various sources as I piece together what I need for this homepage.

The result on the front end is currently a blank white screen. The custom post type and metaboxes add/edit/save fine on their own. It's just when I have this homepage template code in there that it's blank.

Any ideas?

Template Name: Homepage

@package _tk

get_header(); ?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

<div class="entry-content">     
    <?php $args = array( 'post_type' => 'films', 'posts_per_page' => 12 );
          $the_query = new WP_Query( $args ); ?>

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

            <?php /* Get the current post ID. */
                    global $post;
                    $post_id = $post->ID;
                  /* If we have a post ID, proceed. */
                    if ( !empty( $post_id ) ) { ?>

                        <h2><?php the_title(); ?></h2>

                        <div class="film_wrap"><?php echo wp_oembed_get( esc_html( get_post_meta( $post_id, $prefix . 'film_embed', true ) ) ); ?></div>

                        <?php if ( get_post_meta( $post_id, $prefix . 'film_textarea', true ) ) : ?>
                            <div class="film_description">
                                <p><?php echo get_post_meta( $post_id, $prefix . 'film_textarea', true ); ?></p>
                        <?php endif; ?>

                        <?php wp_reset_postdata(); ?>

                    <?php } else { ?>

                        <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>

                    <?php } ?>

     <?php wp_link_pages( array(
            'before' => '<div class="page-links">' . __( 'Pages:', '_tk' ),
            'after'  => '</div>',
        ) ); ?>

<?php endwhile; ?>

</div><!-- .entry-content -->
<?php edit_post_link( __( 'Edit', '_tk' ), '<footer class="entry-meta"><span class="edit-link">', '</span></footer>' ); ?>
</article><!-- #post-## -->

<?php wp_reset_query(); ?>
<?php get_footer(); ?>

The error message I get from WP_DEBUG is:

Parse error: syntax error, unexpected end of file in /myhost/test/wp-content/themes/ianrigby/homepage.php on line 54

  • What error messages to you get from the results of your basic debugging? Turn on WP_DEBUG and add the resulting error messages to your question. – Otto Sep 4 '14 at 17:10
  • I updated my question with the full template code and the error I'm receiving from WP_DEBUG. – dmoz Sep 4 '14 at 18:27

You start a while loop using the colon syntax, but never end the while loop with endwhile properly. Your template is thus incomplete, and this is what is giving you the syntax error.

  • Do you have an example using the code above? I've closed using endwhile; (see my edit) but I still get a blank page. Sorry for the ignorance. I've been staring at this block of code too long. – dmoz Sep 5 '14 at 18:24
  • I missed having to also close the endif; right after the endwhile;. Working now, thanks! – dmoz Sep 5 '14 at 18:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.