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

zaraki kenpachi
zaraki kenpachi
2,331 Points

Portfolio page not showing portfolio images

I already follow all the instruction but it seem my page not showing any of portfolio images. Kindly please help me

below is my 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>
    </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() ?>

2 Answers

Stephen O'Connor
Stephen O'Connor
22,291 Points

Try 'post_type' in your WP_Query arguments array, not 'post-type'.

zaraki kenpachi
zaraki kenpachi
2,331 Points

i already change to 'post_type' but nothing happen. Still not display the thumbnail

Stephen O'Connor
Stephen O'Connor
22,291 Points

What's with the mark down on the answer? :O 'post_type' is the correct syntax, not 'post-type', I don't think this merits a markdown as the original code posted was incorrect.

zaraki kenpachi
zaraki kenpachi
2,331 Points

functions.php

<?php

add_theme_support('menus');
add_theme_support( 'post-thumbnails' ); 

function register_theme_menus() {

    register_nav_menus(
        array(
            'primary-menu' => _('Primary Menu')
        )
    );

}

add_action ('init', 'register_theme_menus');

function wpt_theme_styles() {

    wp_enqueue_style( 'foundation_css', get_template_directory_uri() . '/css/foundation.css' );
    //wp_enqueue_style( 'normalize_css', get_template_directory_uri() . '/css/normalize.css' );
    wp_enqueue_style( 'googlefont_css', 'http://fonts.googleapis.com/css?family=Asap:400,700,400italic,700italic)' );
    wp_enqueue_style( 'main_css', get_template_directory_uri() . '/style.css' );

}

add_action( 'wp_enqueue_scripts', 'wpt_theme_styles');

function wpt_theme_js() {

    wp_enqueue_script( 'modernizr_js', get_template_directory_uri() . '/js/modernizr.js', '','', false);
    wp_enqueue_script( 'foundation_js', get_template_directory_uri() . '/js/foundation.min.js', array('jquery'),'', true);
    wp_enqueue_script( 'main_js', get_template_directory_uri() . '/js/app.js', array('jquery', 'foundation_js'),'', true);
}
add_action( 'wp_enqueue_scripts', 'wpt_theme_js');

?>

already changed as your suggestion :

<?php 

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

?>
Stephen O'Connor
Stephen O'Connor
22,291 Points

Try taking the quote marks off the $args parameter in your wp_Query.

<?php

    $args = array(
          'post_type' => 'portfolio'
     );

     $query = new WP_Query( $args );

?>

And try this for your loop, I'm not sure you need the first '$query->' on 'have_posts'.

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

// your code

<?php endwhile; endif; wp_reset_query(); ?>
zaraki kenpachi
zaraki kenpachi
2,331 Points

now i can see the thumbnails by removing quote marks off. thank you so much :)

Stephen O'Connor
Stephen O'Connor
22,291 Points

Excellent. Glad it's working for you now.

Don Hamilton III
Don Hamilton III
31,828 Points

I was having a similar problem and this was exactly the problem. lol. Thanks for the help Stephen.

THANK YOU!!!!

'post_type', not 'post-type'!

This was my problem.

In the admin area, go to CPT UI plugin -> Add/Edit Post types -> Edit Post Types. Scroll down till end, you will see a section called Supports and check Title .