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

PHP How to Build a WordPress Theme WordPress Theme Functions The WordPress Loop

The Wordpress Loop and adding it

So I'm working on the loop and it is the strangest thing - when you view the front-page.php without any loop code in there the text is visible. Once you add the loop in and then view the page, it is a blank white page. You cannot see any of the content.

Here is my front-page.php with the loop :

    <?php get_header(); ?>

           <p>This this the front-page.php</p>

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


    <h3><? php the_title(); ?></h3>
    <?php the_content(); ?>
    <hr>

<?php endwhile; else: ?>

    <p>There are no posts or pages here</p>

<?php endif; ?>


<?php get_footer(); ?>

Any suggestions?

p.s. while working in sublime text, it says I'm writing in html but when you go to change it to php is says php is already checked....would this have anything to do with it?

2 Answers

Kevin Korte
Kevin Korte
28,149 Points

You have an error.

This line

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

You have an extra space between the ? and php. It should be

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

I just made the exact same error on my testbed WP site and I lost the whole loop.

As long as your file extension is PHP, you're fine. Submlime's language selector is just for proper syntax highlighting.

Thanks so much, it is always the spacing that throws ya off! I figured it was just for highlighting but I just wanted to make sure.

Thanks again!