WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use this script to display recent posts:

<?php query_posts('showposts=5'); ?>

<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>

<li><?php the_content_limit(250); ?></li>
<?php endwhile;?>

I put this in the header.php. It does the job, but also all other posts and pages gets messed up. When I try to load any ordinary page (page.php) I get only content from two blog posts and similar problems. It is not the issue with the_content_limit. I also tried excerpt - and its the same.

Any ideas how to avoid the problem but still have recent posts?

share|improve this question
up vote 1 down vote accepted

Add this after your endwhile

 <?php wp_reset_query() ?>


share|improve this answer
Thanks! It helped. – user385917 Jan 28 '12 at 21:03
you are welcome, as a little advise, is always a good practice to place a reset after your loop, so this way it won't crash is you are using anu other queries around like sidebars, footer, header among others, have fun :) – andresmijares25 Jan 29 '12 at 3:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.