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 trialCarla Thomas
Front End Web Development Techdegree Student 16,039 PointsWP loop not working
I am using the loop below in WordPress but it is not pulling all of the 4 posts onto one page.
I have changed all pages to use the same custom template.
The custom template is working.
If anyone has insight to this problem please share.
Thanks in advance.
<?php
/**
* Template Name: One Page Site
*
* @package One Page Theme
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
TEST!!!!!!
<?php
$args = array(
'post_type' => 'page',
'order' => 'ASC');
$the_query = new WP_Query( $args );
?>
<?php if ( have_posts() ): while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php endwhile; endif; ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Francesco Debiaggi
655 PointsCheck your code
1 Answer
Muhammad Mohsen
Courses Plus Student 10,843 PointsHi Carla,
You just forgot to add $the_query if ( $the_query->have_posts() ) :
Carla Thomas
Front End Web Development Techdegree Student 16,039 PointsThanks Muhammad.
I already tried that and it didn't work. The above code is the code from the "One Page Site" tutorial.
Francesco Debiaggi
655 PointsFrancesco Debiaggi
655 PointsCheck your code