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 trialbuckaroobanzai
482 PointsPosts don't appear in WordPress theme.
I have been following along with the WordPress theme development lessons, designing my own theme based on a static website design.
Everything was working correctly until I added the loop code. My header and footer appear, and the css seems to be working correctly. However, the div where my posts should be is completely blank.
I've double-checked my header, footer, index, and function files, but I still can't figure it out. Does anyone have any suggestions?
Here is my index.php file, for reference:
<?php get_header(); ?>
<section class="row">
<div class="small-12 columns text-center">
<div class="leader">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php endwhile; else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
</div>
</div>
</section>
<?php get_footer(); ?>
2 Answers
Robert Mehew
2,427 PointsIn your loop there is nothing to show any data.
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php endwhile; ?>
Compared to something like this:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
Good luck!
Jeff Lemay
14,268 PointsWhat is the "_e" for in your else statement? You don't need to come in and out of php tags for that anyways:
<?php endwhile; else : ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
Jeff Lemay
14,268 PointsSorry, didn't notice this was for WP. I see why you used _e
buckaroobanzai
482 PointsNo problem, thanks anyways.
buckaroobanzai
482 Pointsbuckaroobanzai
482 PointsIt worked, thank you very much!