Title: While Loop Limit Post Issue
Last modified: August 19, 2016

---

# While Loop Limit Post Issue

 *  [KX254F](https://wordpress.org/support/users/kx254f/)
 * (@kx254f)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/while-loop-limit-post-issue/)
 * I understand php enough to get my self into trouble. Right now I’m in trouble.
   I want to pull 3 posts from a category by using a while loop. Right now it doesn’t
   limit it to 3. What am I doing wrong?
 * Here’s the code.
 * <?php query_posts(‘cat=4’); ?>
    <?php if (have_posts()) : $count = 0; ?> <?php
   while (have_posts()) : the_post(); $count <= 2; $count++; ?>
 * </h4>
    <p class=”post-details”><?php _e(‘Posted on’,woothemes); ?> <?php the_time(‘
   d. M, Y’); ?> | ” rel=”bookmark” title=”Read More”>Read More
   
    <hr />
 * <?php endwhile; ?>
    <?php endif; ?>

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

 *  Thread Starter [KX254F](https://wordpress.org/support/users/kx254f/)
 * (@kx254f)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/while-loop-limit-post-issue/#post-1769291)
 * Part of it was missing. Nothing crucial but wanted to re-post.
 * <?php query_posts(‘cat=4’); ?>
    <?php if (have_posts()) : $count = 0; ?> <?php
   while (have_posts()) : the_post(); $count <= 2; $count++; ?>
 * </h4>
    <p class=”post-details”><?php _e(‘Posted on’,woothemes); ?> <?php the_time(‘
   d. M, Y’); ?> | ” rel=”bookmark” title=”Read More”>Read More
   
    <hr />
 * <?php endwhile; ?>
    <?php endif; ?>
 *  Thread Starter [KX254F](https://wordpress.org/support/users/kx254f/)
 * (@kx254f)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/while-loop-limit-post-issue/#post-1769292)
 * Never mind. it’s just making links when I post because of the href’s
 *  Thread Starter [KX254F](https://wordpress.org/support/users/kx254f/)
 * (@kx254f)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/while-loop-limit-post-issue/#post-1769299)
 * Anyone?
 *  Thread Starter [KX254F](https://wordpress.org/support/users/kx254f/)
 * (@kx254f)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/while-loop-limit-post-issue/#post-1769306)
 * I solved it. If anyone finds this down the road. This is what I did.
 * Added this to the query: &posts_per_page=3
 * So now it looks like this:
 * <?php query_posts(‘cat=4&posts_per_page=3’); ?>
    <?php if (have_posts()) : $count
   = 0; ?> <?php while (have_posts()) : the_post(); $count <= 2; $count++; ?>
 *  [mrkeroppi](https://wordpress.org/support/users/mrkeroppi/)
 * (@mrkeroppi)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/while-loop-limit-post-issue/#post-1769643)
 * Seeing as this thread was so lonely, thought I would just say thanks KX254F.

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

The topic ‘While Loop Limit Post Issue’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 2 participants
 * Last reply from: [mrkeroppi](https://wordpress.org/support/users/mrkeroppi/)
 * Last activity: [15 years, 5 months ago](https://wordpress.org/support/topic/while-loop-limit-post-issue/#post-1769643)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
