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

Tristan Swartz
Tristan Swartz
4,290 Points

Portfolio pieces were empty [solved]

My issue was that my pieces were all running off of my index.php, we hadn't set up any single.php yet and therefore nothing could properly display the piece information.

1 Answer

Tristan Swartz
Tristan Swartz
4,290 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>
<p>test</p>
        <?php the_content(); ?> 

<?php endwhile; endif; ?>

        </div>
        </div>
</section>

<?php 

  $num_posts = ( is_front_page() ) ? 4 : -1;

  $args = array(
    'post_type' => 'portfolio',
    'posts_per_page' => $num_posts
  );
  $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(); ?>

There's my template php, is there anything else you need?

Tristan Swartz
Tristan Swartz
4,290 Points

After doing a bit more digging around, the problem doesn't appear to be the code, it's going off my index.php file... Only, unlike in the video, ,I've is not giving out any static page... Hopefully after I create my single-portfolio.php everything will straighten lut.