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

Loop isn't displaying img icon

Having a bit of an issue with getting the loop to work. Before applying the loop I can see the broken image icon leading to the "Sorry...." page. After applying the if while and query statements then closing them the image icon disappears.

I've also tried <?php echo "jfkdjkfjs"; ?> That showed on the page but I'm not sure what I did wrong.

Lastly the CPT UI slug has the name "portfolio"

<?php 
/*
Template Name: Portfolio Page

*/

?>
<?php get_header( $name );?>



<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; else : ?>
                    <p><?php _e( 'Sorry, no page found.' ); ?></p>
                <?php 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">
          <p>Test</p>
          <a href="item.html"><img src="assets/img/temp/item-01.png" alt=""></a>
        </div>

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


    </section>  

<?php get_footer( $name );?>

2 Answers

I don't think you need $name in your

<?php get_header( $name );?>
```. I believe you just need to have ```<?php get_header(); ?>```

changed it but to no avail

Did you set a featured image for the portfolio?

melissa brown
melissa brown
4,670 Points

hey did you figure it out? im having the same problem