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 Coding Your Own Custom Post Type Templates

Cesare Parmiggiani
Cesare Parmiggiani
8,017 Points

Something does not work

This i my page-portfolio.php:

<?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>
</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(); ?>

The article content doesn't appear in the page.

I got even an issue in add new article:

there are only description and imagesn not title

Cesare, which portion is not working? Is the_content not working near the top? Or is the custom post type query not working? Try to be as descriptive as possible with what the issue is, it will help other forum members more effectively help you resolve the problem. Thank you!

3 Answers

Cesare Parmiggiani
Cesare Parmiggiani
8,017 Points

Hi mikes02! Sry and thank you for your answer.

I try to explain better:

I see the page, but the wp query does not work, i can't see the content post and the thumbnail.

hey Cesare Parmiggiani ,

Actually my code looks the same and I've got same problem the content doesn't appear on a page-portfolio page. I wonder have you solved that problem?

Enrico Imbalzano
Enrico Imbalzano
2,879 Points

The code looks good to me... Since page-portfolio.php actually shows a grid of the portfolio custom posts using just the featured images (retrieved with the the_post_thumbnail() function), did you check to see if you've correctly added the featured image to each portfolio post?