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

Priyanka Swadi
Priyanka Swadi
2,663 Points

Only latest post displayed on the blog page and not the subsequent ones

I have multiple posts on the site and I have set my posts page in wordpress to Blog. But I only see the latest post and not the subsequent posts. Here is my home.php :

<?php get_header(); ?>

<div class="container">
<div class="row">

  <div class="col-md-9">

    <div class="page-header">
      <h1><?php wp_title(''); ?></h1>
    </div>

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

      <article class="post">

        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
        <p>
          By <?php the_author(); ?> 
          on <?php echo the_time('l, F jS, Y');?>
          in <?php the_category( ', ' ); ?>.
          <a href="<?php comments_link(); ?>"><?php comments_number(); ?></a>
        </p>

        <hr>

        <?php the_excerpt(); ?>

      </article>


    <?php endwhile; else: ?>

      <div class="page-header">
        <h1>Oh no!</h1>
      </div>

      <p>No content is appearing for this page!</p>

    <?php endif; ?>


  </div>

  <?php get_sidebar( 'blog' ); ?>

</div>

<?php get_footer(); ?>

1 Answer

You need to create a while loop and invoke WP Query to have the posts. Also you "should" have a template part to reference the posts' HTML.

Priyanka Swadi
Priyanka Swadi
2,663 Points

But I don't see wp_query used either in the tutorial video or the project downloads. Which is why I wondered what I was doing wrong. Thank you for your feedback though.