Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I use this script to display recent posts:

<ul>
<?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;?>
</ul>

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
add comment

1 Answer

up vote 1 down vote accepted

Add this after your endwhile

 <?php wp_reset_query() ?>

Regards

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
add comment

Your Answer

 
discard

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.