WordPress WordPress Theme Development Custom Post Type Templates in WordPress The Portfolio Homepage

Andrew Davies
Andrew Davies
6,884 Points

Images not displaying on Portfolio Page and Permalink linking to "Hello World" Post

I'm missing something obvious and vital here but having looked through all the questions on this video I haven't found an answer.

I have two issues that I think must be linked.

Firstly, I cannot get thumbnail images to display on the portfolio page. I have added

"add_theme_support( 'post-thumbnails' );"

to my functions.php file as instructed. The "add_theme_support( 'menus' );" function works fine.

Featured images is enabled and displaying when I add the Portfolio Piece.

In the absence of the image I added a text link which did display but the link address is

"http://localhost/localwp.dev/2018/07/13/hello-world/"

and not "http://localhost/localwp.dev/portfolio_wadn/pink-triangle/" (Hello Weezer fans)

So I know I am missing something because the Portfolio page is not finding the right slug/address to link to the post.

Can anyone help, my dog is looking at me strangely because I keep sighing and throwing my hands up in the air. The code I have is below:

functions.php code:

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

function wadn_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( 'app_js', get_template_directory_uri() . '/js/app.js', array('jquery', 'foundation_js'), '', true );  

}
add_action( 'wp_enqueue_scripts', 'wadn_theme_js' );





?>

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>
    </section>

<?php 

    $args = array(
        'post-type' => 'portfolio_wadn'
    );
    $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(); ?>">Test</a>
      </div>    

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

</section>

<?php get_footer(); ?>
Andrew Davies
Andrew Davies
6,884 Points

Found the problem.

Had typed

 'post-type' => 'portfolio_wadn'

When I should have posted

 'post_type' => 'portfolio_wadn'

with an underscore, not a hyphen.

I love coding.

1 Answer

Glenré Charl Labuschagné
Glenré Charl Labuschagné
23,199 Points

I made exactly the same mistake: thanks for sharing!!!