Posted By

rliverman on 01/30/11


Tagged

wordpress pagination multiple loops


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

baires
virendrakryadav
acousins
TinekeinTOWN
jamiebrwr


Multiple Loops and Pagination in Wordpress


 / Published in: PHP
 

Needed this to have the index.php or main blog page show the full content for the first two posts and then just the excerpt for the rest and still have pagination working.

  1. <?php
  2. $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
  3. query_posts("paged=$page&posts_per_page=5"); ?>
  4.  
  5. <?php $count = 1; // Sets count to 1 on first output post ?>
  6.  
  7. <?php while (have_posts()) : the_post(); ?>
  8.  
  9. <?php if ((!is_paged()) && ($count == 1 || $count == 2)){ // THIS STARTS FULL CONTENT IF IS FIRST POST AND NOT PAGED, THE OR OTHER COUNT ALLOWS FOR SHOWING MORE THAN ONE OF THE FULL CONTENT POSTS BEFORE GOING TO EXCERPTS ?>
  10.  
  11. <?php the_content(); ?>
  12.  
  13. <?php } else { // THIS ends FULL CONTENT and SHOWS FOLLOWING POSTS ELSE ?>
  14.  
  15. <?php the_excerpt(); ?>
  16.  
  17. <?php } $count++; // THIS IS the END of ELSE and sets count one up ?>
  18.  
  19.  
  20.  
  21. <?php endwhile; ?>
  22.  
  23. <div class="navigation">
  24. <div class="next-posts"><?php next_posts_link('&laquo; Older Entries') ?></div>
  25. <div class="prev-posts"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
  26. </div>

Report this snippet  

You need to login to post a comment.