Title: Repeating Content &#8211; query_posts problem
Last modified: August 18, 2016

---

# Repeating Content – query_posts problem

 *  Resolved [Lindsey](https://wordpress.org/support/users/lalindsey/)
 * (@lalindsey)
 * [18 years, 7 months ago](https://wordpress.org/support/topic/repeating-content/)
 * Hello,
 * I’ve stared at this for the last hour and can’t figure out what the problem is,
   so maybe a pair of fresh eyes will be able to spot what is wrong.
 * So, I’m using query_posts to call different numbers of posts from different categories
   on my pages. This has worked without any problems so far. For example on my index
   page I have two content boxes which display certain content from 2 seperate categories.
   Than in my sidebar I have used it to display the last three posts from another
   category.
 * So, what I want to do next is use it for my navigation to control the list of
   title links to the posts. So this is the code I have used:
 *     ```
       <ul id="nav">
       	<li><a href="<?php echo get_option('home'); ?>" class="home">Home</a></li>
           <li><a href="/about" class="about">About</a></li>
           <li><a href="/services" class="services">Services</a></li>
           <li><a href="#" class="athletes">Athletes</a>
       		<ul>
       		<?php query_posts('showposts=20&cat=5'); ?>
               <?php while (have_posts()) : the_post(); ?>
       			<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a></li>
                <?php endwhile; ?>
       		</ul>
       	</li>
       	<li><a href="/timetables" class="timetables">TimeTables</a></li>
           <li><a href="/blog" class="blog">Blog</a></li>
           <li><a href="#" class="contact">Contact</a></li>
       </ul>
       ```
   
 * But, when I place this code in my header.php file, and upload it to the site 
   all the pages and posts point to the last post in category id #5. For some reason
   I guess the loop isn’t ending for that section, but I’m not sure why? Is it because
   it’s in my header.php file? When I remove the code from my header.php file everything
   returns to normal.
 * Suggestions, ideas, solutions?
 * Thanks!
    Lindsey

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

 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [18 years, 7 months ago](https://wordpress.org/support/topic/repeating-content/#post-635252)
 * When you do a query_posts(), you overwrite the old query. In other words, there’s
   one active query at a time, and you’ve overriden it with your query.
 * You need to reset the query before your main Loop. Try adding this just before
   your main Loop:
    `query_posts($query_string);`
 *  Thread Starter [Lindsey](https://wordpress.org/support/users/lalindsey/)
 * (@lalindsey)
 * [18 years, 7 months ago](https://wordpress.org/support/topic/repeating-content/#post-635271)
 * Ah great. That worked. Thanks so much. I knew it would be something simple that
   I overlooked.
 *  [ivovic](https://wordpress.org/support/users/ivovic/)
 * (@ivovic)
 * [18 years, 7 months ago](https://wordpress.org/support/topic/repeating-content/#post-635272)
 * Otto is a rock star 🙂
 *  [kurisukun](https://wordpress.org/support/users/kurisukun/)
 * (@kurisukun)
 * [18 years, 7 months ago](https://wordpress.org/support/topic/repeating-content/#post-635589)
 * Don’t forget to make sure that $query_string is accessible with `global $query_string;`
   before `query_posts($query_string);`

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

The topic ‘Repeating Content – query_posts problem’ is closed to new replies.

## Tags

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

 * 4 replies
 * 4 participants
 * Last reply from: [kurisukun](https://wordpress.org/support/users/kurisukun/)
 * Last activity: [18 years, 7 months ago](https://wordpress.org/support/topic/repeating-content/#post-635589)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
