Title: Posts &amp; Category display
Last modified: October 4, 2021

---

# Posts & Category display

 *  [digstertron](https://wordpress.org/support/users/digstertron/)
 * (@digstertron)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/posts-category-display/)
 * Hello,
 * I’m learning how to write loops and what not, problem is I am trying to create
   a custom category page, I’ve managed to slowly write a query to pull in 5 posts
   from a specific category but it’s only displaying one. Is there anything wrong
   with my code below? (obviously there is!).
 *     ```
       <?php
   
       get_header('topbar'); ?>
   
       <div class="blog_container">
       		<h2 class="blog-title">
       		Latest News
       		</h2>
       	<p>
       		News information and much more.
       	</p>
       </div>
   
       <?php
               // the query
               $the_query = new WP_Query(array(
       					'category_name' => 'my-category-slug',
                   'post_status' => 'publish',
                   'posts_per_page' => 6,
               ));
               ?>
   
               <?php if ($the_query->have_posts()) : ?>
                   <?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
                       <?php the_category(', '); ?>
                       <?php the_title(); ?>
                       <?php the_excerpt(); ?>
                       <?php the_post_thumbnail(); ?>
                       <?php the_content(); ?>
   
                   <?php endwhile; ?>
                   <?php wp_reset_postdata(); ?>
   
   
               <?php endif; ?>
   
       	<div class="container bloglist">
   
       				<div class="blog_list_outter">
       					<div class="blog_author">
       							<div class="author_image"><?php echo get_avatar( get_the_author_meta('ID'), 60); ?></div>
       					</div>
   
       					<div class="post-grid">
       						<h2 class="blog_heading">
       							<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
       						</h2>
       							<div class="category_title">
       										<div class="category__list__card">
       												<p class="cat">
       													<?php echo get_the_category_list(', '); ?>
       												</p>
       										</div>
       										<div class="post__stamp">
       													<?php the_time('F j, Y'); ?>
       										</div>
       							</div>
       					</div>
       			</div>
       	</div>
   
       <?php get_footer();
   
       ?>
       ```
   

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [corrinarusso](https://wordpress.org/support/users/corrinarusso/)
 * (@corrinarusso)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/posts-category-display/#post-14925419)
 * Are you sure you have more than one post that meets this criteria:
    ‘category_name’
   => ‘my-category-slug’, ‘post_status’ => ‘publish’,
 * You need to print the post out inside the if and while – right now you are printing
   out the post outside the loop.
    Like this: [https://postimg.cc/PpXfxMHx](https://postimg.cc/PpXfxMHx)
 *  Thread Starter [digstertron](https://wordpress.org/support/users/digstertron/)
 * (@digstertron)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/posts-category-display/#post-14925540)
 * Hi there,
 * Yes I have four posts under a category called ‘Test’ but it’s only displaying
   one post inside aforementioned category.
 * Not sure I understand what you mean by going outside of the loop?
    -  This reply was modified 4 years, 8 months ago by [digstertron](https://wordpress.org/support/users/digstertron/).
 *  [corrinarusso](https://wordpress.org/support/users/corrinarusso/)
 * (@corrinarusso)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/posts-category-display/#post-14925917)
 * Here – try this:
    [https://pastebin.com/N1SX5R3y](https://pastebin.com/N1SX5R3y)
 *  Thread Starter [digstertron](https://wordpress.org/support/users/digstertron/)
 * (@digstertron)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/posts-category-display/#post-14935341)
 * Excellent! That works! Thank you 🙂

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Posts & Category display’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [digstertron](https://wordpress.org/support/users/digstertron/)
 * Last activity: [4 years, 8 months ago](https://wordpress.org/support/topic/posts-category-display/#post-14935341)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
