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

WordPress

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(); ?>
<hr>

<?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!