Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2012
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. <?php
  2. // page totals
  3. $first_page_total= 5; // total number posts on first page
  4. $paginated_total = 20; // total number of posts on paginated pages
  5.  
  6. // get the current category ID
  7. $current_category = get_query_var('cat');
  8.  
  9. // pagination for custom page(s)
  10. if ( get_query_var('paged') ) { $paged = get_query_var('paged'); }
  11. elseif ( get_query_var('page') ) { $paged = get_query_var('page'); }
  12. else { $paged = 1; }
  13.  
  14. $args1 = array(
  15. 'order' => 'DESC',
  16. 'post_status' => 'publish',
  17. 'cat' => $current_category,
  18. 'paged' => $paged
  19. );
  20.  
  21. if(!is_paged()) {
  22. $args1['posts_per_page'] = $first_page_total;
  23. $args2 = array('cat' => $current_category,'offset' => $first_page_total, 'posts_per_page' => $paginated_total);
  24. $fake_query = new WP_Query( $args2 );
  25. $paginate_query = array('query' => $fake_query);
  26. wp_reset_postdata();
  27. $the_query = new WP_Query( $args1 );
  28.  
  29. } else {
  30. $args1['posts_per_page'] = $paginated_total;
  31. $offset = $first_page_total + ($paginated_total*($paged-2));
  32. $args1['offset'] = $offset;
  33. $the_query = new WP_Query( $args1 );
  34. $paginate_query = array('query' => $the_query);
  35.  
  36. }
  37.  
  38. $found_posts = $paginate_query['query']->found_posts;
  39.  
  40. //correct the max number of pages
  41. $pages = 0;
  42. for ($i=0; $i < $found_posts; $i += $paginated_total) {
  43. // first page
  44. if($i == 0){ $i = $first_page_total; ++$pages; }
  45. ++$pages;
  46. }
  47. $paginate_query['query']->max_num_pages = $pages;
  48. ?>
  49.  
  50. <?php
  51. if ( $the_query->have_posts() ) :
  52.  
  53. // pagenavi before the the loop
  54. wp_pagenavi($paginate_query);
  55.  
  56. // Start of the Loop
  57.  
  58. ?>
  59. <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
  60. <?php get_template_part('content', get_post_format()); ?>
  61. <?php endwhile; ?>
  62.  
  63. <?php
  64. // pagenavi after the loop
  65. wp_pagenavi($paginate_query);
  66. ?>
  67.  
  68. <?php else : ?>
  69. <h1 class="entry-title">Nothing Found</h1>
  70. <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement