Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


Trent Burkenpas
Trent Burkenpas
22,388 Points

Wordpress Loop

I can not for the life of me get the wordpress loop to work. I check and check and check the code. I made sure all the files were in the right place. It just will not work. Here is my code.

<?php get_header(); ?>

<p>This is the front-page.php file.</p>

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

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

<?php endwhile; else: ?>

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

<?php endif; ?>

<?php get_footer(); ?>

So when i go to run the site all it says is

"This is the header This is the front-page.php file"

4 Answers

You should post this in a Gist instead of in the page, complex PHP pages do not show up well in forum.

One mistake I see is when your loop opening is wrong.

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

The second one is missing an "s", have_posts is what it should read.

Matt Campbell
Matt Campbell
9,767 Points

Tip for copying in long pieces of PHP, indent everything in your editor before copying. When it comes over here, it retains that tabbed in-ness so all of it shows up as code. :)

And yes, missing the s!