Sticky Posts ignores 'posts_per_page'
-
Hi,
I am in middle of coding a theme and stuck!!This is the code I am using to get the latest posts.
$args = array( 'posts_per_page'=> 6, 'paged' => $paged ); query_posts($args); if (have_posts()) : while (have_posts()) : the_post(); ?> <div class="home-widgets"> <?php if ( has_post_thumbnail() ) { the_post_thumbnail('recent');} <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <p><?php echo get_the_content();?></p> <div class="cread"><a href="<?php the_permalink(); ?>">Continue →</a></div> </div> <?php endwhile; ?>
Now, when I have sticky posts, the query ignores the ‘posts_per_page’ argument. For example, if I have two sticky posts, the number of displayed posts becomes 8 (where I set the ‘posts_per_page’ to 6).
I got it partially fixed by adding this code;
$pagenow = (get_query_var('paged')) ? get_query_var('paged') : 1; if ($pagenow == 1){$count = $num - 1;} else {$num = $count;} $args = array( 'posts_per_page'=>$count, 'paged' => $paged );
That breaks the pagination. It is adding an extra page after the last page which resulting in a “Not Found” posts page.
So, is there any way of doing it properly?
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Sticky Posts ignores 'posts_per_page'’ is closed to new replies.