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

Ian Mackenzie
Ian Mackenzie
11,062 Points

My Portfolio Images are not showing

<?php get_header(); ?>

<?php
/*
Template Name: Portfolio Page
*/
?>

<section class="row">
    <div class="small-12 columns text-center">

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <div class="leader">
            <h1><?php the_title(); ?></h1>
            <?php the_content(); ?>
            <?php endwhile; endif; ?>
        </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(); ?>

3 Answers

Ian Mackenzie
Ian Mackenzie
11,062 Points

I've since resolved this problem. When I created the custom post for the portfolio piece there was no title field?

When you create your custom post type in the backend of wordpress using the Custom Post Type version UI 1.0.8 plugin make sure you go to settings section and make sure in the supports section you have TITLE and Featured image selected.

This video really needs to be updated to mention these issues, it would have saved me a couple of hours of my time. It's not mentioned in the video above at all.

geoffrey
geoffrey
28,736 Points

Glad you found a way to fix this issue.

Thank you, Ian. When I was going through the steps, I didn't have the field to set the Featured Image. Your fix was the answer I was looking for. Thanks!

Thank you Ian.

geoffrey
geoffrey
28,736 Points

Check the console of your browser and see what happens. For example the path to your images might be wrong, in that case, the console of your browser would print 404 errors as an example. To check that using chrome press, f12 and select the network tab.

Ian Mackenzie
Ian Mackenzie
11,062 Points

Ok, thanks I'll try that out.

Caden Adam
Caden Adam
16,257 Points

Hey Ian, this is pretty late but to fix it, just add an <img/> before the_post_thumbnail

<a href="<?php the_permalink(); ?>"><img /><?php the_post_thumbnail( 'large' ); ?></a>