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!
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
benjamin holmes1,064 Points
I'm having serious issues with getting my portfolio images to display. Its making me sad.
Have been stuck on this tutorial for a while now and it's really becoming problematic as I have tried the original code in the video and also read all of the questions and answers and none have helped. Really need to be able to crack on with this particular course for my internship. Having the issue of my portfolio images not displaying, have tried the code in the video and also an answer to a similar question that suggested to change the post_type to portfolio_piece, to no avail. Please help me!
Here is my page-portfolio.php code
<?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> <?php the_content(); ?> <?php endwhile; endif; ?> </div> </div>
$arg = 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(); ?>
<?php get_footer(); ?>
benjamin holmes1,064 Points
I worked it out guys. The code from the tutorial is fine. It's certainly not explained in the tutorial but that is probably just due to it being a couple of years ago. Basically in the portfolio CPT UI (custom post type) make sure you tick the custom field box in the the 'Supports'. That allows the CPU UI and the Custom Fields to link. Best of luck to all of you dudes!
David Evans10,490 Points
It seems others are having the same issues as you in this thread here: https://teamtreehouse.com/community/my-images-wont-appear-on-portfolio-page
David Soards on Aug 25, 2017 might have a solution for you.
so i figured it out! The new verions of Custom Post Types will not let you name the post type "Portfolio" because there is already a page with that name. I named mine "portfolio_piece" Therefore the 'post_type' => 'portfolio_piece' instead of 'Portfolio'
<?php $args = array( 'post_type' => 'portfolio_piece' ); $query = new WP_Query( $args ); ?>
Hopefully this helps for you as your code looks fine.