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 Single Page

Carl Sergile
Carl Sergile
16,570 Points

Sidebar doesn't show in single-portfolio.php/Nothing shows but the title.

cc: Zac Gordon

I'm having the same problem with my code. For some reason the sidebar isn't displaying on the single-portfolio.php page. If anyone has a code that works can they paste copy and paste it for everyone to use?

<?php /* Temeplate Name: Single Page */ ?>

<?php get_header(); ?>

<section class="two-column row no-max pad"> <div class="small-12 columns"> <div class="row">

          <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <!-- Primary Column -->
        <div class="small-12 medium-7 medium-offset-1 medium-push-4 columns">
          <div class="primary">

          <?php the_field('images'); ?>
    </div>
  </div>


      <!-- Secondary Column -->
  <div class="small-12 medium-4 medium-pull-8 columns">
          <div class="secondary">

              <h1><?php the_title(); ?></h1>
              <p><?php the_field('description'); ?></p>

              <hr>

              <p>
                <?php previous_post_link(); ?>
                  <a href="<?php bloginfo(); ?>/portfolio">Back to Portfolio</a>
          </div>
      </div>
      <?php endwhile(); endif; ?>
    </div>
  </div>

</section>

<?php get_footer(); ?>

Gary Burton
Gary Burton
11,087 Points

I am getting the same thing, its something to do with the line the_field('description'); I havent figured out the solution yet, but if you change that line to the_content(); content displays so you know that wordpress is looking at the right file.

2 Answers

Hello! I was having the same issue. I followed the code, went through the questions here and still couldn't find what the problem was. all it is showing is the title. No sidebar and no images.

Initially there was an issue with setting up the CPT UI when it won't allow me to use "portfolio" as the Post Type Slug so I used "portfolios".

Then on the page-portfolio.php, when declaring the post type, I used "portfolios to match the CPT UI.

<?php

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

?>

What I didn't realize was wordpress uses single-$posttype.php (based on the template hierarchy), therefore the file name for the single-$posttype.php should be the same as the one used on your CPT UI and the one declared on the page-portfolio.php.

TL:DR

make sure these are the same:

  1. Post type Slug on the CPT UI
  2. declaration on page-portfolio.php
  3. filename for your single-$posttype.php

I hope this helps. Took me a while but i'm happy that I can now move one.

Nice one..:-)

Thanks bro, really helped me out, exactly what I needed..

I had the exact same issue with choosing the post type slug name in CPT UI. I named mine 'portfoliopost'. I corrected the initial issue with WP_Query, however I ran into yet another issue when naming my single portfolio page 'single-portfolio.php', rather than 'single-portfoliopost.php'. Anyways, nice catch - Very helpful! Thank you.

Also, this post was 6months ago. How's everyone journey been since this was posted? Are you using WordPress currently to develop websites?