Different numbers of posts on different pages
-
Hi,
I’m currently building a theme where, on the first page of the theme, I’m showing 3 posts, then on page 2 or higher, I want to show 12 posts.
I use the following code to grab the page number and change my loop settings (as the styles are very different from frontpage to page 2).
<?php if ( !is_single() && $paged > 1 ) { ?> <!-- This is for pages after the frontpage, so page numbers > 1. --> <div id="maincontent2"> <div id="loopheader2"> <?php echo previous_posts_link( __( '<< Newer posts' ) ); ?> <div id=nextpost> <?php next_posts_link( __( 'Older posts >>') ); ?> </div> <!--id="nextpost" --> </div> <!--id="loopheader" --> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <div id="older"> <?php attachment_image_or_postthumb('thumbnail'); ?> <br /> <div style="text-indent:10px;"> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a> </div> <!-- style="text-indent:10px;" --> </div> <!--id="older" --> <?php endwhile; ?> <?php endif; ?> <br /> </div> <!-- id="maincontent" --> <!-- This is where the if switches to the first page --> <?php } else { ?> <div id="maincontent"> <div id="loopheader"> <? echo "Latest Posts"; ?> <div id=nextpost> <?php next_posts_link( __( 'Older posts >>',0 ) ); ?> </div><!--id="nextpost" --> </div> <!--id="loopheader" --> <?php if (have_posts()) : $count = 0; ?> <?php while (have_posts()) : the_post(); ?> <div <?php if($counter==0) { echo 'id="first"'; $counter++; } else { echo 'id="rest"'; $counter++; } ?>> <?php attachment_image_or_postthumb('thumbnail'); ?> <br /> <div style="text-indent:10px;"> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a> </div> <!-- style="text-indent:10px;" --> </div> <!--id="older" --> <?php endwhile; ?> <?php endif; ?>
I’ve tried using the Custom Post Limits plugin by coffee2code but when I do the next posts link disappears on page 2, despite there being more than 15 posts.
I’ve tried using query_posts and showposts but when I get to page 2 its starts on post 13.
Can anyone suggest a solution?
- The topic ‘Different numbers of posts on different pages’ is closed to new replies.