Want more features on Pastebin? Sign Up, it's FREE!

Posts_per_page & wp_paginate

By: Twansparant on Sep 5th, 2011  |  syntax: PHP  |  size: 1.51 KB  |  views: 827  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
  3. $max_first_page = 3;
  4. $posts_per_page = 4;
  5. $posts_to_skip = $posts_per_page - $max_first_page;
  6.        
  7. if ($page == 1) {
  8.         $max_posts = $max_first_page;
  9. } else {
  10.         $max_posts = $posts_per_page;
  11.         $offset = (($page - 1) * $max_posts)- $posts_to_skip;
  12. }
  13.        
  14. $args = array(
  15.         'posts_per_page' => $max_posts,
  16.         'post_type' => 'news-item',
  17.         'offset' => $offset,
  18.         'paged' => $paged
  19. );
  20. $temp = $wp_query;
  21. $wp_query= null;
  22. $wp_query = new WP_Query($args);
  23.  
  24. $style_classes = array('first','second');
  25. $style_index = 0;
  26. ?>
  27.  
  28. <?php if (have_posts()) : ?>
  29.         <?php $post = $posts[0]; $c=0; ?>
  30.         <?php while ($wp_query->have_posts()) : $wp_query->the_post();?>
  31.                 <?php $c++;     if( !$paged && $c == 1) : ?>
  32.                                
  33.                                 <div class="most-recent-post">
  34.                                 // First large post on first page
  35.                                 </div>
  36.  
  37.                         <?php else: ?>
  38.                                
  39.                                 <div class="post-block <?php $k = $style_index%2; echo "$style_classes[$k]"; $style_index++; ?>">
  40.                                 // Normal posts
  41.                                 </div>
  42.                                
  43.                 <?php endif;?>
  44.         <?php endwhile; ?>
  45. <?php endif; ?>
  46.  
  47.  
  48. <!-- page nav -->
  49. <div class="page-navi">
  50.         <?php
  51.                 $numposts = $wp_query->found_posts; // Total number of posts
  52.                 $numpages = 1 + ceil(($numposts - $max_first_page) / $posts_per_page); // Total number of pages
  53.                 $pagenr = (get_query_var('paged')) ? get_query_var('paged') : 1;
  54.         ?>
  55.         <?php if(function_exists('wp_paginate')) {
  56.         wp_paginate('page='.$pagenr.'&pages='.$numpages);
  57.         } ?>
  58. </div>
  59. <?php $wp_query = null; $wp_query = $temp;?>
clone this paste RAW Paste Data