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

Jeffrey Cunningham
Jeffrey Cunningham
5,592 Points

Unable to register featured image section.

<?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' );

?>

Can someone help me debug this. I'm not getting the featured image section in my post type.

2 Answers

Manuel Schulze
Manuel Schulze
12,739 Points

The featured image section is not appearing on your portfolio section, correct?

Custom Post Type UI changed a little since the course has been made. Now you need to go to the 'CPT UI' section on your admin panel and select: 'Add/Edit Post Types'. Then select 'Edit Post Types' Tab and scroll down to the bottom of that page. Now you need to select 'Featured Image' checkbox on the right-hand side. Lastly go to the top again and click the 'Save Post Type' button.

Now the featured image section should've been visible again.

I'll hope this will help you and it's not too late ;)

Jeffrey Cunningham
Jeffrey Cunningham
5,592 Points

Thanks Manuel, The issue was actually that the CPT field plugin was setting the field name to images_ and I had it coded as images.

Manuel Schulze
Manuel Schulze
12,739 Points

Why do you need an extra field for this featured image? Normally if you setup CPT plugin correctly it will show you the featured image section automatically. Maybe I just don't understand what you mean with 'images_'.

But I can use the featured image by using the WordPress function the_post_thumbnail('large');

I don't need the Advanced custom field plugin to handle this because it's integrated in WordPress automatically.

Thanks for the help. This should definitely be in the teacher's notes.

Jeffrey Cunningham
Jeffrey Cunningham
5,592 Points

Sorry Manuel Schulze, I didn't explain this clearly in the question because I didn't know what was going on. The issue was actually in the single-porfolio.php template. In order to display the image we use the Custom fields plugin specific function php the_field(); Here you pass a parameter of the field name given by the plugin in order to display it.

I was passing it a parameter of "images" as I saw in the video, but then when I took a look in the plugin UI. I saw that it was giving my images field a field name of "images_".

I hope that explains it.

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

This answer was very helpful to me just now. I just wanted to add though after experimenting I found that you do still need the php code in the functions.php file. Just to reinforce this... :)

add_theme_support('post-thumbnails');
Jeffrey Cunningham
Jeffrey Cunningham
5,592 Points

Sorry this should show the code better

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' );

?>```

Thanks Manuel! I was having the same problem and I appreciate the help!