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 came across a strange problem while working on my dev environment for a site we're making. We have custom post types, so I'm not sure if that's the reason why it's not working correctly. However, I managed to get the posts to display 5 at a time instead of normal 10. However, in one of the categories, it only displays 10 out of 20 posts. What's weird is that if I go to a different category, it'll run correctly.

    <?php echo category_description(); ?> 
<?php if (have_posts()) : ?> 
<?php $i = 0; while (have_posts() && $i < 5) : the_post(); ?> 
<div class = "post">
  <h3 class="listing-<?php the_ID(); ?>"> <br>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"> <?php the_title(); ?> </a>   </h3>  </br> 
<div class = "city"> <b> City:</b> <?php $City = get_post_meta($post->ID, 'City', true); echo $City;?>   </div>
<div class = "price"> <b> Price:</b> <?php $Price = get_post_meta($post->ID, 'Price', true); echo $Price;?> </div> 
<b>Rating:</b>
<div class = "rating">  <?php wp_gdsr_render_article(); ?> </div>
</div>   <br>
</br>
<?php $i++; endwhile; ?>
<div class="navigation">
 <div class="alignleft">
<?php previous_posts_link(); ?>
<?php next_posts_link(); ?>
</div>

Answer: Thanks for the help everyone!

The way to get around it is to go to: WP Dashboard > Settings > Reading and change the number at "blog pages show at most" option to the number of pages to display.

share|improve this question
    
The number of post displayed is controlled first by the number set in the reading settings and can be overridden in your query using posts_per_page –  Chris_O May 6 '11 at 17:32
add comment

1 Answer

up vote 2 down vote accepted

The problem is that your query is selecting 10 posts per page, but you're only limiting the view to 5, so you're losing 5 posts per page. The proper way to change the number of posts per page is to modify the query before the loop:

<?php
$myquery = wp_parse_args($query_string);
$myquery['posts_per_page'] = 5;
query_posts($myquery);
    if (have_posts()) : // etc.
share|improve this answer
    
Thanks Chris and Milo - unfortunately after I tried the query posts_per_page it remains the same. For the category I'm having issues with, I noticed it says "Nothing found..for category...page 3." –  Nina May 6 '11 at 17:48
    
have you changed while (have_posts() && $i < 5) to while (have_posts()) to verify that posts per page is being set correctly? –  Milo May 6 '11 at 18:10
    
Sorry, I did change it back to while (have_posts()) but it didn't do anything different. It still displayed up to 10 posts_per_page, but never makes it to 20 posts. –  Nina May 6 '11 at 18:33
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.