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 WordPress Theme Development Custom Post Type Templates in WordPress The Portfolio Homepage

Loop not starting - (Images and other markup do not display)

Ok so this is a similar issue with the rest of the people asking. I can't get the images to show. But none of the other markup in the loop shows up as well. All I am getting in the loop is the section element. Contents within the section elements doesn't display.

<?php
/*
    Template Name: Portfolio Page
*/
?>
<?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(); ?>

            <h1><?php the_title(); ?></h1>
            <p><?php the_content(); ?></p>        

        <?php endwhile; else : ?>

            <p><?php _e( 'Sorry, no pages found.' ); ?></p>

        <?php endif; wp_reset_postdata(); ?>

        </div>
    </div>
</section>

<?php 

    $args = array(
        'post_type' => 'portfolio',
    );
    $query = new WP_Query( $args );

?>

<section class="row no-max pad">

    <?php if( $query->have_posts() ) : while( $query->have_posts ) : $query->the_post(); ?>
    <div class="small-6 medium-4 large-3 columns grid-item">
        <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('large'); ?></a>
    </div>

    <?php endwhile; endif; wp_reset_postdata(); ?>
</section>

<?php get_footer(); ?>

Hey there everyone! I figured out the issue with this. It was the loop was missing a parenthesis. Also if you are not seeing featured images, but do see your markup when you inspect the code being outputted, you can just go to the admin area and checkmark the options in the CPT UI section for portfolio. That all did it for me and I have everything working properly. If you are experiencing issues still. Just copy and paste the files from the finished project files over one at a time until you see everything working properly then you can sift through the code until you spot the discrepancy. I figured out it was an issue with my code by activating the finished project theme, when I saw everything working, I knew the issue was with the code in my theme.

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