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

My portfolio page is only displaying 6 out of the 10 posts

Ok, so I have no clue what is going on with my site. Towards the end of the video, Zac asks to add additional portfolio posts to the portfolio page to make sure it works with multiple posts. I made 10 new posts using the custom portfolio template, but when I view the site, only 6 show up. I double checked to make sure I wasn't missing anything when creating the posts, like the featured image, and they still don't show up.

The 6 that do show up work as expected. I am also not getting any console errors and I've gone back over the last 3 videos multiple times to make sure I'm not missing any code, but no matter what I do I only get 6 posts on the portfolio page. I have provided my code below that is relevant. There are a lot of files in this video and I didn't want to upload everything, but let me know if I missed an important file. Thanks in advanced!

Page.php

<?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>
        <h6>By: <?php the_author(); ?></h6>
        <p><?php the_content(); ?></p>
    <?php endwhile; else : ?>
        <p><?php _e('Sorry, no pages found.'); ?></p>
    <?php endif; ?>
    </div>
  </div>
</section>



<?php
  get_footer();
?>

page-portfolio.php

<?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' => 'my_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">
      <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('large'); ?></a>
    </div>
  <?php endwhile; endif; wp_reset_postdata(); ?>
</section>
<?php
  //loads footer.php
  get_footer();
?>

functions.php

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

?>

1 Answer

Hi Amber,

Try going in the admin under Settings > Reading and changing blog pages to show for example 10 and see if that changes it.

Sometimes it overlaps with the "blog pages show at most" setting.

Mark

Yay Mark!! you are a lifesaver! works perfectly now. Thanks so much!

Hi Amber,

I am glad that fixed it for you. There are other ways to approach it but if you are not running posts like that on any other page that is the easiest way and keeps it admin controlled.

Very Welcome! Mark