Title: Loop: Posts from a single category ID
Last modified: August 19, 2016

---

# Loop: Posts from a single category ID

 *  [MonicaW](https://wordpress.org/support/users/monicaw/)
 * (@monicaw)
 * [16 years, 5 months ago](https://wordpress.org/support/topic/loop-posts-from-a-single-category-id/)
 * I am using categories to separate posts in navigation. For instance, I have an“
   Advice Centre” link in the navigation that I want to only pull in posts from 
   that category. The problem is, it only displays the first one, and not any of
   the others.
 * The code I am using is:
 *     ```
       <h2>Advice Centre</h2>
       		<?php $posts = get_posts( "category=1" ); ?>
   
       		<?php while (have_posts()) : the_post(); ?>
       			<div class="post">
       				<h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
       				<div class="entry"><?php the_excerpt(); ?></div>
       			</div>
       		<?php endwhile; ?>
       ```
   
 * I would be very happy if someone could show me where I’ve gone wrong – thanks
   in advance.

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

 *  Thread Starter [MonicaW](https://wordpress.org/support/users/monicaw/)
 * (@monicaw)
 * [16 years, 5 months ago](https://wordpress.org/support/topic/loop-posts-from-a-single-category-id/#post-1282811)
 * I’ve finally answered my own question, but I’ll post the answer here in case 
   anyone else has managed to make the same mistake. 🙂
 * Change the first line to:
 *     ```
       <?php query_posts('cat=1&showposts='.get_option('posts_per_page')); ?>
       ```
   
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [16 years, 5 months ago](https://wordpress.org/support/topic/loop-posts-from-a-single-category-id/#post-1282843)
 * `showposts` won’t be supported for much longer, use this instead..
 *     ```
       <?php
       $paged = get_query_var('paged') ? get_query_var('paged') : 1;
       query_posts('cat=1&paged='.$paged.'&post_per_page='.get_option('posts_per_page'));
       ?>
       ```
   
 * It will allow your query to work with paging to..
 * NOTE: You can also use the category name if you prefer, with the following..
 *     ```
       category_name=NAME
       ```
   
 * in place of..
 *     ```
       cat=X
       ```
   
 * …in the query_posts line 😉
 *  [HumbleRat](https://wordpress.org/support/users/humblerat/)
 * (@humblerat)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/loop-posts-from-a-single-category-id/#post-1283167)
 * Add
    `<?php query_posts('category_name=NAMEOFCATEGORY'); ?>` before The Loop
 * The category can also be designated by it’s ID instead of it’s name by using “
   cat=4” where “4” equals the category’s ID.
 * For more information see:
    [http://codex.wordpress.org/Function_Reference/query_posts#Category_Parameters](http://codex.wordpress.org/Function_Reference/query_posts#Category_Parameters)

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

The topic ‘Loop: Posts from a single category ID’ is closed to new replies.

## Tags

 * [category loop](https://wordpress.org/support/topic-tag/category-loop/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 3 participants
 * Last reply from: [HumbleRat](https://wordpress.org/support/users/humblerat/)
 * Last activity: [15 years, 7 months ago](https://wordpress.org/support/topic/loop-posts-from-a-single-category-id/#post-1283167)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
