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

Walter Perez
Walter Perez
11,383 Points

page-portfolio not showing images !

Hello community! I'm calling thumbnail exactly as Zac in the video... What about you? Here you have my code.. Any help would be appreciated.

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

    <?php get_header();

    ?>

    <?php

    $args = array(

        'post_type' => ' portfolio'

    );

    $query = new WP_Query ( $args );

    ?>

    <div class="content portfolio-preview">


        <h2>Ver portfolio</h2><small>-Web- -DiseƱo- -IlustraciĆ³n- -Social Media- -S.E.O- -S.E.M-</small>  

        <div class="container content">

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

            <div class="c_6 item">

                <img src="<?php the_post_thumbnail('large') ?>" alt="<?php the_title()?>">


                    <div class="item-name content">

                    <div class="c_8">

                        <h3><a href="<?php the_permalink()?>"></a><?php the_title()?></h3>

                    </div>

                    <div class="c_4">

                        <h3>Zoom</h3>

                    </div>

                </div>

                <span class="tech-used">

                    <ul>

                        <li><?php  echo the_category()  ?></li>

                    </ul>

                </span> 

            </div>

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

        </div>

     </div> 
    <?php get_footer(); ?>

26 Answers

nguyen manh
nguyen manh
16,824 Points

You using the_post_thumbnail wrong way. It not return image src, it return img tag. Ex:

<?php the_post_thumbnail(); ?> return: <img src="example.com/img/treehouse.jpg" alt="">
nguyen manh
nguyen manh
16,824 Points

I think you need remove space before portfolio post type

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

->

$args = array( 'post_type' => 'portfolio' );
Paul Shryock
Paul Shryock
6,291 Points

I was stuck for a while, but this line fixed it for me:

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

I had this line split up into multiple lines as in the video, but that didn't work. Making it all one line fixed the problem.

nguyen manh
nguyen manh
16,824 Points

So you can't see Featured image select on the right in portfolio?

Click CPT UI in admin menu -> choose tab 'Edit Post Types' -> select custom post type you want to enable featured img (select box on the left) -> scroll down to bottom, you can see on the right side have Supports field -> check Featured images -> now you should see Featured image section on custom post type

Walter Perez
Walter Perez
11,383 Points

This step was one of the first I did.. but i've done again, and everything is checked.. but still doesn't work. I don't know what else to do... 1 day 1 problem...

nguyen manh
nguyen manh
16,824 Points

You can add this code to check post has thumbnail:

if ( has_post_thumbnail() ) {
    the_post_thumbnail();
        // you should use chrome dev tool to check return value
        // and change define('WP_DEBUG', true) in wp-config.php, it'll display error if something wrong.
}
else {
    echo 'post thumbnail not set';
       // maybe you forgot set post thumbnail;
}

let me know result.

nguyen manh
nguyen manh
16,824 Points

upon file you send to me. just add add_theme_support( 'post_thumbnails' ) to functions.php and follow image(link updated).

I was test on local and post thumbnail work well.

nguyen manh
nguyen manh
16,824 Points

You welcome, I'm just student like you. Try and fail is normal in web dev field, as long as you do not give up.

Good luck! :)

Walter Perez
Walter Perez
11,383 Points

Then thank you a lot. You can add me to walcolorful@gmail.com and we can talk about dev students topics or whatever.

I'm a little bit confused, let me know if i'm wrong.. But.. we are paying a subscription, and after 2 days, I have not received any help... Are we paying just for a the videos? is not teacher support included..?

nguyen manh
nguyen manh
16,824 Points

Maybe teachers have alot of work, they still answer some topic.

If you feel confused, I think better is watch video again and follow step by step until you fully understand. Learn new skill need patient. Another great tutorial for make WordPress theme

Caden Adam
Caden Adam
16,257 Points

Hey Walter, what you have to do - I assume you've checked the boxes in CPT UI panel - is add an <img /> tag just before the_post_thumbnails();

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

this worked for me.

Walter Perez
Walter Perez
11,383 Points

can't see the example friend!

Caden Adam
Caden Adam
16,257 Points
<a href="<?php the_permalink(); ?>"><img /><?php the_post_thumbnail( 'large' ); ?></a>

sorry haven't replied to anything before so not sure. does this work?

Caden Adam
Caden Adam
16,257 Points
<?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(); ?>"><img /><?php the_post_thumbnail( 'large' ); ?></a>
      </div>

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

    </section>

<?php get_footer(); ?>

this is my page-portfolio.php

Walter Perez
Walter Perez
11,383 Points

Thank you so much for the response. Then, if it returns the tag, should i show it like this ? Still not working...

'''html

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

<?php get_header();

?>

<?php

$args = array(

'post_type' => ' portfolio'

);

$query = new WP_Query ( $args );

?>

<div class="content container portfolio-preview">

<h2>Ver portfolio</h2><small>-Web- -DiseƱo- -IlustraciĆ³n- -Social Media- -S.E.O- -S.E.M-</small>  

<div class="container content">

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

    <div class="c_6 item">

        <?php the_post_thumbnail( 'large' ); ?>

        <div class="item-name content">

            <div class="c_8">

                <h3><a href="<?php the_permalink()?>"></a><?php the_title()?></h3>

            </div>

            <div class="c_4">

                <h3>Zoom</h3>

            </div>

        </div>

        <span class="tech-used">

            <ul>

                <li><?php  echo the_category()  ?></li>

            </ul>

        </span> 

    </div>

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

</div>

</div>

<?php get_footer(); ?>

Walter Perez
Walter Perez
11,383 Points

I really appreciate your help, but still doesn't work... here is the code:

''''html <?php
/* Template Name: Portfolio
*/ ?>

<?php get_header();

?>

<?php

$args = array(

'post_type' => 'portfolio'

);

$query = new WP_Query ( $args );

?>

<div class="content container portfolio-preview">

<h2>Ver portfolio</h2><small>-Web- -DiseƱo- -IlustraciĆ³n- -Social Media- -S.E.O- -S.E.M-</small>  

<div class="container content">

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

    <div class="c_6 item">

        <?php the_post_thumbnail( 'large' ); ?>

        <div class="item-name content">

            <div class="c_8">

                <h3><a href="<?php the_permalink()?>"></a><?php the_title()?></h3>

            </div>

            <div class="c_4">

                <h3>Zoom</h3>

            </div>

        </div>

        <span class="tech-used">

            <ul>

                <li><?php  echo the_category()  ?></li>

            </ul>

        </span> 

    </div>

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

</div>

</div>

<?php get_footer(); ?>

Walter Perez
Walter Perez
11,383 Points

It throws me there is not thumbnail. I tried using add_theme_support for thumbnails , but neither works. Thumbnails in plugins also checked. Debug modified to true, and not throw any message through the console.. Could be something wrong with my functions.php?

Walter Perez
Walter Perez
11,383 Points

or something missing...

'''php

<?php

//INCLUDING MENUS

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

function register_theme_menus(){

register_nav_menus(

    array(

            'primary-menu' =>__( 'Primary Menu' ),
            'footer-menu' =>__( 'Footer Menu' )

        )

);

}

add_action('init','register_theme_menus');

// INCLUDING STYLES

function colorful_theme_styles(){

wp_enqueue_style('main_css', get_template_directory_uri() . '/style.css' );

}

add_action( 'wp_enqueue_scripts', 'colorful_theme_styles' );

// INCLUDING JAVASCRIPT

function colorful_theme_js(){

wp_enqueue_script( 'main_js', get_template_directory_uri() . '/js/app.js', array('jquery'),'',true); 

}

add_action('wp_enqueue_scripts','colorful_theme_js');

?> '''

nguyen manh
nguyen manh
16,824 Points

If you do not mind, you can install backup plugin, then backup both database and files and send to me. I'll check this in free time.

Walter Perez
Walter Perez
11,383 Points

Here you have my files

Thank you soo much for your time.

nguyen manh
nguyen manh
16,824 Points

You send me wrong file. file is wordpressbackup plugin not wordpress site + database

Walter Perez
Walter Perez
11,383 Points

The choices i have in admin is: Just files. Just database. Or both. Which one should I send?

nguyen manh
nguyen manh
16,824 Points

send me both file + database

Walter Perez
Walter Perez
11,383 Points

That's what i've tried to share before, but i sent the wrong link. Here it is. New Link

nguyen manh
nguyen manh
16,824 Points

I don't have permission to download this file

nguyen manh
nguyen manh
16,824 Points

Hmm... I still only permission to view, can't download, you need check again

Walter Perez
Walter Perez
11,383 Points

I did it, but still doesn't work.

Perhaps, as I didn't started with a child theme, i have missing some code.. because I can't understand... I will start from a child theme and test. Although I would like to know what is happening here..

Thank you so much nguyen. You are great partner.. or you are from treehouse team?

Walter Perez
Walter Perez
11,383 Points

thank you for your support, it doesn't work..

If there's someone who can send me a code working, to check it out and compare.. I'm blocked here since 2 weeks... =( so sad

Walter Perez
Walter Perez
11,383 Points

Still doesn't work... Maybe i should try send the question to Zac..

nguyen manh
nguyen manh
16,824 Points

Oh, I thought you closed topic 1 month ago.

This is link to working post thumbnail code: https://www.dropbox.com/s/u9f8kcmshnhc47u/localhostwpt_forum-1439540074-complete-2015-09-23-14-08-18.zip?dl=0

Make sure you change wp_config.php correct with your information.